各ファイルのgrep出力間隔の設定

各ファイルのgrep出力間隔の設定

複数のファイルをgrepするとき、複数のファイルに私が探している単語が含まれていると、出力が順番に出てくるので読みにくいです。とにかく、各ファイルの出力を一致させた後に追加の\ nを挿入できますか?

たとえば、私が得た現在の出力は

$ grep word daily_log.201407*
<daily_log.20140702-matches  about 100 lines>
<daily_log.20140704-matches  about 10 lines>
<daily_log.20140706-matches  about 50 lines>

次のことを達成しようとしています。

$ grep word daily_log.201407*
<daily_log.20140702-matches  about 100 lines>


<daily_log.20140704-matches  about 10 lines>


<daily_log.20140706-matches  about 50 lines>

質問が明確になりますように。これを行う方法はありますか?

ベストアンサー1

各ファイルをgrepし、grepの結果に応じて追加の行を追加できます(つまり、一致しないファイルを除く)。

for fn in daily_log.201407* ; do
grep word "$fn"
if [ $? == 0 ] ; then
   echo -e '\n\n\n'
fi
done

おすすめ記事