I spent several days for this simple issue and can't get solition!
I have a log, and there are several rows per second. I need only one row per second - and it isn't matter, which one.
Example log:
23:59:58 Incoming packet DeviceId:42FF223F23AC
23:59:58 Incoming packet DeviceId:42FF223F23AC
23:59:58 Incoming packet DeviceId:42FF223F23AC
23:59:59 Incoming packet DeviceId:42FF223F23AC
23:59:59 Incoming packet DeviceId:42FF223F23AC
23:59:59 Incoming packet DeviceId:42FF223F23AC
I need this:
23:59:58 Incoming packet DeviceId:42FF223F23AC
23:59:59 Incoming packet DeviceId:42FF223F23AC
I tried cat log | uniq -w8
cat log | uniq -w8
, but it doesn't work
I'm very sorry of my English - it's not my native language. PS Solution on another script language (like PHP, Python) is fine too
This should do it:
cat inputFile | sort | uniq -w8
or
sort inputFile | uniq -w8
As uniq
is only comparing the first 8 characters, which are hh:mm:ss
如果时间字段是您确定一行是否与前一行不同时唯一需要考虑的事情,您可以使用这个 oneliner awk 来完成:
awk -F ' ' '{if ($1 != time_prev) {print $0;} time_prev=$1}' < yourfile.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.