nc10@your-5554c55be4 ~
$ cat sheet
server 127.0.0.1 localhost connected yes 12-3-08
server 127.0.0.1 localhost connected no 12-3-08
server 127.0.0.1 localhost connected yes 14-9-09
server 127.0.0.1 localhost connected yes 15-9-09
server 127.0.0.1 localhost connected no 16-9-09
nc10@your-5554c55be4 ~
$ sed '/^server.*$/s//&test/g' sheet
server 127.0.0.1 localhost connected yes 12-3-08 test
server 127.0.0.1 localhost connected no 12-3-08 test
server 127.0.0.1 localhost connected yes 14-9-09 test
server 127.0.0.1 localhost connected yes 15-9-09 test
server 127.0.0.1 localhost connected no 16-9-09 test
nc10@your-5554c55be4 ~
$
希望没理解错你的意拆枝思,轿御枝闭敏呵呵
如果文件这样也可的,因为 /^server/ 限定了 只是行头是
server 才在行尾插入字符
user@minix-nb:~$ cat sheet
remote 127.0.0.1 localhost connected yes 12-3-08
server 127.0.0.1 localhost connected no 12-3-08
remote 127.0.0.1 localhost connected yes 14-9-09
server 127.0.0.1 localhost connected yes 15-9-09
remote 127.0.0.1 localhost connected no 16-9-09
user@minix-nb:~$ sed '/^server.*$/s//&test/g' sheet
remote 127.0.0.1 localhost connected yes 12-3-08
server 127.0.0.1 localhost connected no 12-3-08 test
remote 127.0.0.1 localhost connected yes 14-9-09
server 127.0.0.1 localhost connected yes 15-9-09 test
remote 127.0.0.1 localhost connected no 16-9-09
user@minix-nb:~$
1.多行行首闭宏插入指定字符串
[plain] view plain copy
:1,6 s/^/System.out.println("
:2,$ s/^/System.out.println(" 注:此为2行至尾行
:% s/^/System.out.println(" 注:此为所有行
2.多行行尾插入指定字符串
[plain] view plain copy
:1,6 s/$/")
:2,$ s/$/") 注:此为2行至尾行
:% s/$/") 注:此为所有行
3.删除简裤多行行首指定字符串
[plain] view plain copy
:% s/^.\{16\}
也可以使用以下命令:
[plain] view plain copy
:% s/System.out.println("/
4.删除多行行尾指定字符串
[plain] view plain copy
:% s/")$//g
% 指匹配整个文件,s 是置换的意思,$ 代表匹配行尾的内容,最后的 g 则表示每行轿咐册中匹配到的内容都要置换。
也可以使用以下命令:
[plain] view plain copy
:% s/")/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)