我有这个问题......回答了,也很好。但是,奇怪的是,如果日志文件有一个唯一的最后一行,(即前几个词与前面的行不同)它正确地返回最后一行,tail -n 1 "file"
但如果最后几行与最后一行相似,它返回所有相似的行。
我来给你展示....
它正在读取的文件是...
frame= 1065 fps= 30 q=1.6 size= 11977kB time=35.54 bitrate=2761.1kbits/s
frame= 1081 fps= 30 q=2.7 size= 12174kB time=36.07 bitrate=2765.0kbits/s
frame= 1097 fps= 30 q=2.7 size= 12332kB time=36.60 bitrate=2759.9kbits/s
frame= 1113 fps= 30 q=3.0 size= 12487kB time=37.14 bitrate=2754.4kbits/s
frame= 1129 fps= 30 q=2.4 size= 12652kB time=37.67 bitrate=2751.3kbits/s
frame= 1145 fps= 30 q=2.4 size= 12824kB time=38.20 bitrate=2749.7kbits/s
frame= 1161 fps= 30 q=2.4 size= 12996kB time=38.74 bitrate=2748.1kbits/s
frame= 1176 fps= 30 q=2.7 size= 13162kB time=39.24 bitrate=2747.8kbits/s
frame= 1191 fps= 30 q=2.6 size= 13328kB time=39.74 bitrate=2747.4kbits/s
frame= 1206 fps= 30 q=2.5 size= 13496kB time=40.24 bitrate=2747.5kbits/s
frame= 1222 fps= 30 q=2.5 size= 13685kB time=40.77 bitrate=2749.6kbits/s
frame= 1240 fps= 30 q=4.2 size= 13954kB time=41.38 bitrate=2762.8kbits/s
frame= 1261 fps= 31 q=4.6 Lsize= 14428kB time=42.08 bitrate=2809.1kbits/s
video:13889kB audio:494kB global headers:0kB muxing overhead 0.314239%
$line = `tail -n 1 "$logfile"`;
返回...
video:13889kB audio:494kB global headers:0kB muxing overhead 0.314239%
但是,如果最后一条更独特的线不存在......它会返回:-
frame= 1065 fps= 30 q=1.6 size= 11977kB time=35.54 bitrate=2761.1kbits/s
frame= 1081 fps= 30 q=2.7 size= 12174kB time=36.07 bitrate=2765.0kbits/s
frame= 1097 fps= 30 q=2.7 size= 12332kB time=36.60 bitrate=2759.9kbits/s
frame= 1113 fps= 30 q=3.0 size= 12487kB time=37.14 bitrate=2754.4kbits/s
frame= 1129 fps= 30 q=2.4 size= 12652kB time=37.67 bitrate=2751.3kbits/s
frame= 1145 fps= 30 q=2.4 size= 12824kB time=38.20 bitrate=2749.7kbits/s
frame= 1161 fps= 30 q=2.4 size= 12996kB time=38.74 bitrate=2748.1kbits/s
frame= 1176 fps= 30 q=2.7 size= 13162kB time=39.24 bitrate=2747.8kbits/s
frame= 1191 fps= 30 q=2.6 size= 13328kB time=39.74 bitrate=2747.4kbits/s
frame= 1206 fps= 30 q=2.5 size= 13496kB time=40.24 bitrate=2747.5kbits/s
frame= 1222 fps= 30 q=2.5 size= 13685kB time=40.77 bitrate=2749.6kbits/s
frame= 1240 fps= 30 q=4.2 size= 13954kB time=41.38 bitrate=2762.8kbits/s
frame= 1261 fps= 31 q=4.6 Lsize= 14428kB time=42.08 bitrate=2809.1kbits/s