Perl从特定字符串

时间:2015-07-12 13:30:15

标签: regex perl csv

我有一个csv文件,其格式如下。

09:20:02.063,110.600,110.300,110.600
09:20:08.425,111.600,110.300,110.600
09:21:02.684,111.600,110.300,110.600
09:21:03.188,110.600,110.300,110.600
09:22:05.552,110.600,110.300,110.600
09:22:03.914,113.600,110.300,110.600
09:23:04.282,112.600,110.300,110.600
09:23:05.643,111.600,110.300,110.600
09:24:01.004,111.600,110.300,110.600
09:24:05.369,110.600,110.300,110.600

我想要删除以“09:23”开头的整行 但是数据格式包括Hour:Minute:Second.Millisecond。我很难将Perl用于特定的“Hour:Minute”来删除行。任何建议,谢谢

预期结果

09:20:02.063,110.600,110.300,110.600
09:20:08.425,111.600,110.300,110.600
09:21:02.684,111.600,110.300,110.600
09:21:03.188,110.600,110.300,110.600
09:22:05.552,110.600,110.300,110.600
09:22:03.914,113.600,110.300,110.600
09:24:01.004,111.600,110.300,110.600
09:24:05.369,110.600,110.300,110.600

1 个答案:

答案 0 :(得分:1)

你可以试试这个,

<div class="header">
    <div class="container">
        <div class="header-left">
            <div class="logo">
                <a href="index.html"><img src="images/logo.gif" alt=""/></a>
            </div>
        </div>
        <div class="header-right">
            <p class="right">Welcome Guest<span>Free Register</span><span>Login</span></p>
            <div class="clear"></div>
            <br>
            <select class="right">
                <option>Select Language</option>
                <option>English</option>
            </select>
            <br>
            <div class="clear"></div>
            <br>
            <p class="right">Powered by Google Translate</p>
            <div class="clear"></div>
        </div>
    </div>
</div>

使用grep,

$ perl -lne 'print if !/^09:23\b/' file
09:20:02.063,110.600,110.300,110.600
09:20:08.425,111.600,110.300,110.600
09:21:02.684,111.600,110.300,110.600
09:21:03.188,110.600,110.300,110.600
09:22:05.552,110.600,110.300,110.600
09:22:03.914,113.600,110.300,110.600
09:24:01.004,111.600,110.300,110.600
09:24:05.369,110.600,110.300,110.600