当我以这种方式对多个文件执行grep时,我有:
$ grep "Sh\|Re" To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/*/key_re*
To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/QTNNSimplePredict_HLD_100,100_DOI_12_PG_12_WD_1e-05_SOT_10pair_20090601_20140707/key_results.txt:Sharpe ratio is: -1.6022503031
To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/QTNNSimplePredict_HLD_100,100_DOI_12_PG_12_WD_1e-05_SOT_10pair_20090601_20140707/key_results.txt:Return rate is: -0.2357384
To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/QTNNSimplePredict_HLD_100,100_DOI_12_PG_12_WD_4e-05_SOT_10pair_20090601_20140707/key_results.txt:Sharpe ratio is: 0.822358458311
To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/QTNNSimplePredict_HLD_100,100_DOI_12_PG_12_WD_4e-05_SOT_10pair_20090601_20140707/key_results.txt:Return rate is: -0.0432811
是否可以使结果看起来像
To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/QTNNSimplePredict_HLD_100,100_DOI_12_PG_12_WD_1e-05_SOT_10pair_20090601_20140707/key_results.txt:
Sharpe ratio is: -1.6022503031
Return rate is: -0.2357384
To_10pair_20140708_20160704_TIR_2.4_TSR_2.4_TP_1.0_SP_1.0/QTNNSimplePredict_HLD_100,100_DOI_12_PG_12_WD_4e-05_SOT_10pair_20090601_20140707/key_results.txt:
Sharpe ratio is: 0.822358458311
Return rate is: -0.0432811
答案 0 :(得分:3)
您可以将结果传递给sed:
grep ...key_re* | sed -e '/:Sharpe/{h;s/:.*/:/;p;g;}' -e 's/[^:]*://'