Linux Three Musketeers sed depth practice to explain (on)

and

     It is sed Stream Editor (stream editor) Abbreviation, operation of the filter and is a powerful tool to convert text content. Common CRUD function, filter, take the line.

 2, CRUD

2.1 increase

a append text to the specified line

i Insert text before the specified line

 

 

sed "2a 106,dandan,CSO" person.txt

 

 

 

sed "2i 106,dandan,CSO" person.txt

 

 

 

 More than 2.12 increase lines 

 

sed "2a 106,dandan,CSO\n107,bingbing,CCO" person.txt

 

 

 

 

 2.2 deleted

     d delete the specified row

sed '2d' person.txt 
sed '2,3d' person.txt 
sed '1~2d' person.txt 
sed '1,+2d' person.txt

 

 

 

sed '/zhangyao/d' person.txt 
sed '/Al/d' person.txt 
sed '/C/d' person.txt 
sed '/F/d' person.txt 

 

 

 

sed '/F/,/A/d' person.txt 

 

 

 

sed '/dongdaxia/d' person.txt 
sed '/dongdaxia/,3d' person.txt 
sed '/zhangyao/,3d' person.txt

 

 

 

 

 2.3 改

2.3.1 按行替换

    c  用新行取代旧行

sed '2c 106,dandan,CSO' person.txt 

 

 2.3.2文本替换

     s:单独使用——》将每一行中第一处匹配的字符串进行替换===》sed 命令·

     g:每一行进行全部替换==》sed命令s的替换标志之一,非sed命令

    -i:修改文件内容===》sed软件的选项

sed软件替换模型(方框被替换成三角)

 

 

 

 

 sed 's#zhangyao#wangzijie#g' person.txt

 

 指定行精确修改配置文件,这样可以防止修改多了的地方

sed '3s#3#9#g' person.txt 

 

 

 

 注意:

sed '3s#3#9#g' person.txt    ####后面的g为全局替换,
   不加g 只对一个‘3’进行操作。
单引号、双引号、没有引号的作用:

 

 


 

 

 

  

 

Guess you like

Origin www.cnblogs.com/dongxu2019/p/11576272.html