如何匹配CSV文件中的字符串并使用Shell脚本删除匹配字符串之前的行

时间:2013-12-02 19:14:21

标签: shell csv format using

我的输入文件是CSV,如下所示:

AOD,10:40:00.128820,11:00:00.128820,19:00:00.000000,19:00:00.000000,0,0,0,0,0,0,0,0,0,0,0,0,N
AOD,10:45:00.128820,11:00:00.128820,19:00:00.000000,19:00:00.000000,0,0,0,0,0,0,0,0,0,0,0,0,N

AOD,11:00:00.128820,11:00:00.128820,19:00:00.000000,19:00:00.000000,0,0,0,0,0,0,0,0,0,0,0,0,N
AOD,11:00:02.128831,11:00:00.128831,19:00:00.000000,19:00:00.000000,0,0,0,0,0,0,0,0,0,0,0,0,N
AOD,11:00:03.128842,11:00:00.128842,19:00:00.000000,19:00:00.000000,0,0,0,0,0,0,0,0,0,0,0,0,N

我只需要在start_time 11:00:00及之后开始的行。我必须在11:00:00之前删除这些行。我还有一个结束时间11:00:01。我需要在11:00:01之后删除这些行。我怎么能这样做?

3 个答案:

答案 0 :(得分:0)

我会做像

这样的事情

cat data.txt | grep 'AOD,11:[0-9][0-9]\:[0][0]' > result.csv

答案 1 :(得分:0)

假设您正在查看第二列

awk -F, -v start="11:00:00" -v stop="11:00:01" 'start <= $2 && $2 <= stop'

答案 2 :(得分:0)

sed -n '/^[^,]*,11:00:00/,/^[^,]*,11:00:01/p'