现在我有一个标准输出,由我的程序打印并显示在屏幕上。输出看起来像以下部分:
Parsing command line string 'InputFile = foreman.qcif'.
Parsing command line string 'NumberReferenceFrames = 1'.
Parsing command line string 'QPISlice = 24'.
Parsing command line string 'QPPSlice = 24'.
------------------------------- JM 11.0 (FRExt) --------------------------------
Input YUV file : foreman.qcif
Output H.264 bitstream : test.264
Output YUV file : test_rec.yuv
YUV Format : YUV 4:2:0
Frames to be encoded I-P/B : 150/0
PicInterlace / MbInterlace : 0/0
Transform8x8Mode : 1
-------------------------------------------------------------------------------
Frame Bit/pic QP SnrY SnrU SnrV Time(ms) MET(ms) Frm/Fld Ref
-------------------------------------------------------------------------------
0000(NVB) 168
0000(IDR) 34280 24 39.724 41.720 43.998 286 0 FRM 1
0002(P) 7432 24 38.857 41.565 43.829 402 99 FRM 1
0004(P) 8976 24 38.642 41.275 43.698 409 97 FRM 1
0006(P) 8344 24 38.427 41.266 43.515 407 99 FRM 1
0008(P) 8224 24 38.609 41.082 43.524 413 94 FRM 1
0010(P) 7784 24 38.655 40.991 43.235 406 95 FRM 1
0012(P) 7136 24 38.534 40.687 43.273 411 95 FRM 1
0014(P) 6688 24 38.464 40.756 43.146 410 92 FRM 1
0016(P) 7720 24 38.516 40.585 42.851 410 91 FRM 1
0018(P) 6864 24 38.474 40.631 42.958 411 101 FRM 1
0020(P) 8392 24 38.433 40.607 42.646 415 99 FRM 1
0022(P) 9744 24 38.371 40.554 42.498 416 94 FRM 1
0024(P) 8368 24 38.362 40.531 42.380 417 93 FRM 1
0026(P) 7904 24 38.414 40.586 42.415 418 95 FRM 1
0028(P) 8688 24 38.403 40.523 42.366 418 96 FRM 1
0030(P) 9128 24 38.545 40.390 42.661 416 89 FRM 1
0032(P) 9664 24 38.399 40.538 42.740 413 88 FRM 1
0034(P) 8928 24 38.394 40.590 42.852 414 95 FRM 1
0036(P) 10024 24 38.423 40.562 42.697 415 92 FRM 1
0038(P) 9320 24 38.442 40.389 42.689 414 94 FRM 1
0040(P) 7304 24 38.404 40.487 42.884 410 90 FRM 1
0042(P) 8560 24 38.447 40.590 42.673 411 95 FRM 1
.......
现在我只需要处理SnrY的第4列。
所以,我的问题是如何grep这个rol并将它们存储在data.txt文件中?
然后我可以使用绘图工具或Matlab用这些数据绘制数据趋势。
有什么建议吗?非常感谢您的帮助!
增加:
由于需要从标准输出中选择那些数据,我是否需要在命令行中使用(添加)您提供的命令,使其在输出这些数据时有效 ?
答案 0 :(得分:3)
$ awk '/FRM/ { print $4 }' < in.txt > data.txt
注意:我只是猜测有趣的行包含FRM
。如果不是这种情况,您必须采用不同的方法来识别它们。
答案 1 :(得分:3)
tail -n+17 in.txt | cut -c 23-31
答案 2 :(得分:2)
./cmd_that_generates_results | awk '/^[0-9]/{print $4}' > data.txt
awk 声明的快速细分:
(已更新):解决问题“由于需要从标准输出中选择这些数据,我是否需要在命令行中使用(添加)您提供的命令在输出那些数据时使它工作吗?“
您可以使用管道(|)命令通过管道传递程序的标准输出来使用答案中给出的命令。然后可以使用&gt; 将结果存储到“data.txt”中。
见上面的例子。此页面中的其他解决方案可以使用类似的技术。
答案 3 :(得分:1)
$ ./command | awk 'BEGIN{RS="--+";FS="\n"} END{ for(i=1;i<=NF;i++){if($i ~ /^[0-9]/){m=split($i,a," ");if(a[4]) print a[4]}}}'
39.724
38.857
38.642
38.427
38.609
38.655
38.534
38.464
38.516
38.474
38.433
38.371
38.362
38.414
38.403
38.545
38.399
38.394
38.423
38.442
38.404
38.447
我期待您想要的数据
所以上面只说:将记录分隔符设置为带有短划线“ - ”的行,因此最后一条记录是您需要的全部数据。然后使用换行符作为字段分隔符(FS =“\ n”),每个字段将是每行数据。用空格拆分它们并获得分割线的元素4。这将是你想要的专栏。
答案 4 :(得分:0)
这将匹配第四列中的38.4 *等数字:
grep -E '^([^ ]+[ ]+){3}38.4'