2023-09-12 17:30:16
2024-10-28 12:37:34
hello world python hell abc hello efg
grep hello 1.txt # 结果 hello world abc hello efg
grep hello -v 1.txt # 结果 python hell
grep -i hello <<EOF hello world python hell abc HeLlo efg EOF # 结果 hello world abc HeLlo efg
grep -n hello <<EOF hello world python hell abc hello efg EOF 1:hello world 3:abc hello efg
tree . ├── 1.txt └── a ├── 1.txt └── b └── 1.txt
# 会搜索当前目录下的所有文件 grep -r hello # 不能指定文件 a/b/1.txt:go hello a/1.txt:python hello 1.txt:hello 1.txt:hello world # -l 只显示 匹配的文件名 grep -rl hello a/b/1.txt a/1.txt 1.txt
grep "he.*" 1.txt hello hello world hell he.* grep "he\.\*" 1.txt he.* grep -F "he.*" 1.txt he.*
# -A --after-context # -B --before-context cat example.txt|grep "hello" -A 10 -B 2
grep -c hello 1.txt
grep -w hello <<EOF helloworld hello world abchello xzy EOF
grep -x "hello world" <<EOF hello world hello world hello world ok EOF # 只会匹配到第二行, 第一行 后面有空格 也不行.