0
我在想,如果有人能幫助我簡化shell命令爲一個或兩行首次和最後出現,我們就可以用awk或sed的,以簡化執行,在執行過程中更好的性能被大大appriciated搜索的多模式
輸入文件
PATTERN1 xxx
PATTERN2 xxx
PATTERN3 xxx
PATTERN1 yyy
PATTERN2 yyy
PATTERN3 yyy
PATTERN1 zzz
PATTERN2 zzz
PATTERN3 zzz
我的腳本:
echo "First occurance..."
grep -m1 "PATTERN1" $fileName
grep -m1 "PATTERN2" $fileName
grep -m1 "PATTERN3" $fileName
echo "Last occurance..."
tac $fileName | grep -m1 "PATTERN1"
tac $fileName | grep -m1 "PATTERN2"
tac $fileName | grep -m1 "PATTERN3"
輸出
PATTERN1 xxx
PATTERN2 xxx
PATTERN3 xxx
PATTERN1 zzz
PATTERN2 zzz
PATTERN3 zzz
在此先感謝