以下是处理2到结尾,使用that替换this,并且me替换test,使用分组的时候,用花括号包起来即可。
[root@localhost shell]# cat helloworld.txt
this is test
this is test
this is test
this is test
this is test
[root@localhost shell]# sed '2,${s/this/that/;s/test/me/}' helloworld.txt
this is test
that is me
that is me
that is me
that is me
合并两个文件的内容,如果我们使用cat a.txt >> b.txt
,这种方式是追加写入到文件,有的时候我们并不需要写文件,而是要得到两个文件的所有内容(合并之后的)
[root@localhost shell]# cat a.txt
this is file a
this is file a
[root@localhost shell]# cat b.txt
this is file b
this is file b
[root@localhost shell]# sed '$r a.txt' b.txt
this is file b
this is file b
this is file a
this is file a