grep,过滤命令(5星级)
grep [content] [filename] 只打印参数后全部或部分包含的内容的行
grep -v [content] [filename] 排除参数后全部或部分包含的内容,打印过滤后的行
注:
只是过滤打印功能,不修改原文件。
head命令,tail命令,也可其过滤打印某行功能
例:
cat test.txt
line1
line2
line3
grep line1 test.txt
line1
grep e2 test.txt
line2
grep -v line1 test.txt
line2
line3
grep -v 1 test.txt
line2
line3
grep -v lin test.txt
[nothing]
head -2 test.txt
line1
line2
tail -2 test.txt
line2
line3