perl awk OR sed,在两个时间戳之间搜索 [英] perl awk OR sed, search between two timestamps
问题描述
我有一个带有以下示例文本的文件. (实际文本很大).
I have a file with following sample text. (The actual text is huge).
2014/05/08-19:15:44.544824-<String1>
2014/05/08-19:21:54.544824-<String2>
2014/05/08-19:34:59.564461-<String3>
我必须在两个时间戳之间提取数据,例如19:15:00-19:20:00,依此类推,直到结束为止.我曾尝试使用sed& awk,但是问题在于他们在某些时候会付出一切. (例如,他们将从19:15:00开始提供所有内容-> EOF).我使用的命令是
I have to extract data between two timestamps like 19:15:00 - 19:20:00 and so on until the eof. I have tried using sed & awk, but the problem is that at certain points they give out every thing. (e.g they'd give out everything from 19:15:00 --> EOF). The commands which i used were
awk '/19:15:00/,/19:20:00/' InputFile
和
sed '/19:15:00/,/19:20:00/p' Inputfile.
关于如何在perl或sed&中进行操作的任何想法awk,实际上哪个可行?错误的输出与时间戳的格式有关吗? (只是在想)
Any ideas as how to do it in perl or sed & awk, which might actually work ? Is the wrong output has something to do with the format of the time stamps ? (just thinking)
PS.我正在使用以下代码制作时间戳. (是否有可能由于本地时间功能而发生了?
PS. I am using the following code to make time stamps. (is it possible because of localtime function this is happening ?
$curr = timelocal(0, 0, 0, (split /\//, $ARGV[0])[1], (split /\//, $ARGV[0])[0]-1, (split /\//, $ARGV[0])[-1]);
$currentTime = strftime "%H:%M:%S", localtime($curr);
推荐答案
使用perl单线.记录时间,然后进行比较.
Using a perl one-liner. Capture the time and then just compare.
perl -ne '$t = /(\d+:[\d:.]+)/ ? $1 : undef;
print if $t ge "19:15:00" && $t le "19:20:00";' file.txt
这篇关于perl awk OR sed,在两个时间戳之间搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!