sed 行对象【插入】【追加】【替换】

sed行对象【插入】【追加】【替换】

All these three commands are for line object, not string.

一、Insert

i newlinewords

insert one new line before line positioned by key word


linenumi newlinewords

insert one new line before line i

[braveyly@m-net ~]$ cat sedaci.txt

word

word

word

[braveyly@m-net ~]$sed –e ‘1i Student’ sedaci.txt

student

word

word

word

[braveyly@m-net ~]$sed –e ‘1,2i Student’ sedaci.txt

student

word

student

word

word

[braveyly@m-net ~]$sed –e ‘/w/i Student’ sedaci.txt

student

word

student

word

student

word

[braveyly@m-net ~]$sed –e ‘/d/i Student’ sedaci.txt

student

word

student

word

student

word

二、Apend

The syntax is completely the same with insert.

The difference is that append command puts one new line after line position.


[braveyly@m-net ~]$sed –e ‘/w/a Student’ sedaci.txt

word

student

word

student

word

student

三、Change

The syntax is completely the same with insert and append.

The difference is that change command replace the old line with the new line.

[braveyly@m-net ~]$ cat sedaci.txt

word

word

word

[braveyly@m-net ~]$sed –e ‘1c Student’ sedaci.txt

student

word

word

[braveyly@m-net ~]$sed –e ‘/w/c Student’ sedaci.txt

student

student

student

你可能感兴趣的:(sed)