grep
使用vi或vim创建文件,并输入以下内容:
1. hello world
2. wold hello
3. nothing is important
4. i like movie movie
hello world
wold hello
nothing is important
i like movie movie
grep操作文本中,最常见的几个命令:
- 查找文件中含有指定字符串的行:
grep hello 【文件名】
- 查找文件中不含有指定字符串的行:
grep -v hello 【文件名】
- 用正则表达式匹配含有数字的行:
grep -E "[0-9]" 【文件名】
- 查找文件中含有指定字符串的行以及该行前n行:
grep movie -B n 【文件名】
- 查找文件中含有指定字符串的行以及该行后n行:
grep movie -A n 【文件名】
- 查找文件中含有指定字符串的行以及该行前n行:
grep movie -C n 【文件名】