![각 파일에 대한 grep 출력 간격 설정](https://linux55.com/image/39964/%EA%B0%81%20%ED%8C%8C%EC%9D%BC%EC%97%90%20%EB%8C%80%ED%95%9C%20grep%20%EC%B6%9C%EB%A0%A5%20%EA%B0%84%EA%B2%A9%20%EC%84%A4%EC%A0%95.png)
여러 파일을 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