About SED
sed:Stream EDitor, 流编辑器、也叫行编辑器。  sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),  接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。  然后读入下行,执行下一个循环。如果没有使诸如‘D’的特殊命令,那会在两个循环之间清空模式空间,但不会清空保留空间。  这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。  sed的功能  :主要用来自动编辑一个或多个文件,简化对文件的反复操作,编写转换程序等
Use of SED tools
sed用法:    sed [option]...‘script‘ inputfile....  常用选项:      -n: 不输出模式中的内容至屏幕,不自动打印    -e: 多点编辑    -f: /path/somefile: 从指定文件中读取编辑脚本    -r: 支持使用扩展正则表达式    -i: 编辑原文件,也可以使用-i.bak,先备份后做修改。
Example: 
 
  
  -E: Executes multiple commands, that is, multi-point editing in the above
 
 
 
[[email protected] ~/gawktest]#sed -e ‘s/brown/green/; s/dog/cat/‘ fileThe quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.  #用‘‘来,从而不需要使用分号,不过从开始以‘来编写结尾的时候也需要用‘来结尾[[email protected] ~/gawktest]#sed -e ‘> s/brown/green/> s/dog/cat/‘ fileThe quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.The quick green fox jumps over the lazy cat.
 
 
  
  -F: Read the editing script from the specified file, if there are a large number of commands to be processed can be stored in a text file in a convenient. Later you can use the sed-f filename file
 
 
 
[[email protected] ~/gawktest]#cat script1 s/brown/green/s/fox/elephant/s/over/cobbler/s/dog/cat/[[email protected] ~/gawktest]#sed -f script1 fileThe quick green elephant jumps cobbler the lazy cat.The quick green elephant jumps cobbler the lazy cat.The quick green elephant jumps cobbler the lazy cat.The quick green elephant jumps cobbler the lazy cat.The quick green elephant jumps cobbler the lazy cat.
Address delimitation 
 
  
  1, not to address: the default to the full text processing
2. Single Address:
 
 
 
        2、1 #:指定的行,$: 最后一行          2、2 /pattern/: 被此处模式所能够匹配到的每一行  
 
 
  
  3. Address range:
 
 
 
        3、1  #,#          3、2  #,+#          3、3  /pat1/,/pat2/          3、4  #,/pat1/  
 
 
  
  4, ~: Step forward
Odd lines
 
 
 
[[email protected] ~/gawktest]#seq 1 10 | sed ‘1~2p‘1123345567789910
 
 
  
  4, 2 2~2 even rows
 
 
 
[[email protected] ~/gawktest]#seq 1 10 | sed ‘2~2p‘12234456678891010
Edit command
D Delete a row that matches the pattern space
]#sed ‘/^UUID/d‘ /etc/fstab   删除以UUID开头的行
P Print the current mode space content, appended to the default output, the general Mate-N option to
[[email protected] ~/gawktest]#sed -n ‘/r..t/p‘ /etc/passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
A [\] text appends text to the specified line, enabling multi-line append with \ n
[[email protected] ~/gawktest]#sed  ‘/^UUID/a \ hello sed‘ /etc/fstabUUID=9d14df54-a9ce-4c41-bdbe-dc9d851d11d1 /                       ext4    defaults        1 1 hello sedUUID=eb942a01-ecc7-40f4-ac87-8a1dbb07841e /boot                   ext4    defaults        1 2 hello sedUUID=e49f600c-7f88-4e84-aba2-bb85296647ad /data                   ext4    defaults        1 2 hello sedUUID=b92b7eda-51dc-4e22-a0fc-09f72a542158 swap                    swap    defaults        0 0 hello sed
I [\] text inserts text in front of the specified line
[[email protected] ~/gawktest]#sed ‘/^UUID/i \head hello‘ /etc/fstab head helloUUID=9d14df54-a9ce-4c41-bdbe-dc9d851d11d1 /                       ext4    defaults        1 1head helloUUID=eb942a01-ecc7-40f4-ac87-8a1dbb07841e /boot                   ext4    defaults        1 2head helloUUID=e49f600c-7f88-4e84-aba2-bb85296647ad /data                   ext4    defaults        1 2head helloUUID=b92b7eda-51dc-4e22-a0fc-09f72a542158 swap                    swap    defaults        0 0
c [\] text replaces behavior line or multiline text
[[email protected] ~/gawktest]#sed ‘/^UUID/c \uuid is 0‘ /etc/fstab ## /etc/fstab# Created by anaconda on Thu Jul 19 09:43:42 2018## Accessible filesystems, by reference, are maintained under ‘/dev/disk‘# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#uuid is 0uuid is 0uuid is 0uuid is 0tmpfs                   /dev/shm                tmpfs   defaults        0 0devpts                  /dev/pts                devpts  gid=5,mode=620  0 0sysfs                   /sys                    sysfs   defaults        0 0proc                    /proc                   proc    defaults        0 0
W/path/to/somefile Save mode space matches the line to the specified file
[ro[email protected] ~/gawktest]#sed ‘/^UUID/w /tmp/fstab‘ /etc/fstab [[email protected] ~/gawktest]#cat /tmp/fstabUUID=9d14df54-a9ce-4c41-bdbe-dc9d851d11d1 /                       ext4    defaults        1 1UUID=eb942a01-ecc7-40f4-ac87-8a1dbb07841e /boot                   ext4    defaults        1 2UUID=e49f600c-7f88-4e84-aba2-bb85296647ad /data                   ext4    defaults        1 2UUID=b92b7eda-51dc-4e22-a0fc-09f72a542158 swap                    swap    defaults        0 0
R/path/from reads the text from the specified file to the line in the pattern space
[[email protected] ~/gawktest]#sed ‘6r /etc/issue‘ /etc/fstab ## /etc/fstab# Created by anaconda on Thu Jul 19 09:43:42 2018## Accessible filesystems, by reference, are maintained under ‘/dev/disk‘CentOS release 6.10 (Final)Kernel \r on an \m# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info=
= Print line number for matching lines in pattern space
[[email protected] ~/gawktest]#sed ‘/^UUID/=‘ /etc/fstab ## /etc/fstab# Created by anaconda on Thu Jul 19 09:43:42 2018## Accessible filesystems, by reference, are maintained under ‘/dev/disk‘# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#9UUID=9d14df54-a9ce-4c41-bdbe-dc9d851d11d1 /                       ext4    defaults        1 110UUID=eb942a01-ecc7-40f4-ac87-8a1dbb07841e /boot                   ext4    defaults        1 211UUID=e49f600c-7f88-4e84-aba2-bb85296647ad /data                   ext4    defaults        1 212UUID=b92b7eda-51dc-4e22-a0fc-09f72a542158 swap                    swap    defaults        0 0
! Matching row-fetching anti-processing in pattern space
  [[[email protected] ~/gawktest] #sed '/^uuid/!= '/etc/fstab 12#3#/etc/fstab4# Created by Anaconda on Thu J UL 09:43:42 20185#6# Accessible filesystems, by reference, is maintained under '/dev/disk ' 7# See mans pages Fstab (5), F    Indfs (8), mount (8) and/or Blkid (8) for more INFO8#UUID=9D14DF54-A9CE-4C41-BDBE-DC9D851D11D1/EXT4 Defaults 1 1uuid=eb942a01-ecc7-40f4-ac87-8a1dbb07841e/boot ext4 defaults 1 2uuid=e49 F600c-7f88-4e84-aba2-bb85296647ad/data EXT4 Defaults 1 2uuid=b92b7eda-51dc-4e22-a0fc-09f72a54         2158 Swap swap defaults 0 013TMPFS/DEV/SHM tmpfs defaults                    0 014devpts/dev/pts devpts gid=5,mode=620 0 015sysfs/sys SYSFS defaults 0 016proc/proc proc defaults 0 0
     
Advanced editing commands
        h:把模式空间中的内容覆盖至保持空间中;        H:把模式空间中的内容追加至保持空间中;        g:从保持空间取出数据覆盖至模式空间;        G:从保持空间取出内容追加至模式空间;        x:把模式空间中的内容与保持空间中的内容进行互换;        n:读取匹配到的行的下一行至模式空间;        N:追加匹配到的行的下一行至模式空间;        d:删除模式空间中的行;        D:删除多行模式空间中的所有行;        sed -n ‘n;p‘ file:显示偶数行        sed ‘1!G;h;$!d‘ file:逆向显示文件内容        sed ‘$!N;$!D‘ file:取文件后两行        sed ‘$!d‘ file:取出文件最后一行        sed ‘G‘ file:在每一行后面加一行空白行        sed ‘/^$/d;G‘ file:        sed ‘n;d‘ file:显示奇数行        sed -n ‘1!G;h;$p‘ file:逆向显示文件中的每一行
The SED of the Three Musketeers of Linux