先创建一个测试文件testfile, 如下
1
2
3
4
5
6
7
8
9
10
| $ cat testfile #查看testfile 中的内容
HELLO LINUX!
Linux is a free unix-type opterating system.
This is a linux testfile!
Linux test
Google
Taobao
Runoob
Tesetfile
Wiki
|
数据的搜寻并显示
1
2
3
| $ nl testfile | sed -n '/oo/p'
5 Google
7 Runoob
|
数据的搜寻并删除
1
2
3
4
5
6
7
8
| $ nl testfile | sed '/oo/d'
1 HELLO LINUX!
2 Linux is a free unix-type opterating system.
3 This is a linux testfile!
4 Linux test
6 Taobao
8 Tesetfile
9 Wiki
|
数据的搜寻并执行命令
搜索 testfile,找到 oo 对应的行,执行后面花括号中的一组命令,每个命令之间用分号分隔,这里把 oo 替换为 kk,再输出这行:
1
2
| $ nl testfile | sed -n '/oo/{s/oo/kk/;p;q}'
5 Gkkgle
|
参考资料