我想提取包含來自perf stat輸出的'seconds time elapsed'輸出的行,以查看我正在處理的某些日誌腳本。從終端中的命令輸出中提取單行
我不想將輸出寫入文件,然後搜索文件。我想用'grep'或類似的東西來做。
這是我曾嘗試:
perf stat -r 10 echo "Sample_String" | grep -eE "seconds time elapsed"
因我所得到
grep: seconds time elapsed: No such file or directory
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
echo: Broken pipe
Performance counter stats for 'echo Sample_String' (10 runs):
0.254533 task-clock (msec) # 0.556 CPUs utilized (+- 0.98%)
0 context-switches # 0.000 K/sec
0 cpu-migrations # 0.000 K/sec
56 page-faults # 0.220 M/sec (+- 0.53%)
<not supported> cycles
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
<not supported> instructions
<not supported> branches
<not supported> branch-misses
0.000457686 seconds time elapsed (+- 1.08%)
我想這
perf stat -r 10 echo "Sample_String" > grep -eE "seconds time elapsed"
對於那些我
Performance counter stats for 'echo Sample_String -eE seconds time elapsed' (10 runs):
0.262585 task-clock (msec) # 0.576 CPUs utilized (+- 1.11%)
0 context-switches # 0.000 K/sec
0 cpu-migrations # 0.000 K/sec
56 page-faults # 0.214 M/sec (+- 0.36%)
<not supported> cycles
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
<not supported> instructions
<not supported> branches
<not supported> branch-misses
0.000456035 seconds time elapsed (+- 1.05%)
我是新來的像grep,awk和sed這些工具。我希望有人能幫助我。我也不想將輸出寫入文件,然後搜索文件。
謝謝你,它的工作。 '2&1'是做什麼的,它是什麼意思? –
它將stderr重定向到stdout。看到這篇文章的更多詳細信息:http://stackoverflow.com/a/2342841/2679935 – julienc