Linux text processing Three Musketeers ---- sed

sed as a line editor to edit text

sed to edit the file, but not change the source file

sed works:

  Specifies a text file, a text file to read the contents of each line, is read into the pattern space (PATTERN SPACE), matching text (regular expression) in the pattern space, matching the content of the modified (replaced, delete, modify, print, save)

usage:

  sed [parameters] "sed own independent use format statement" [Text File]

  Parameter options:

    -n reject the default display

    -r specify extended regular expressions

      Match IP

        1, with all that is not

        2, | or

    -e write script

    -f script file specified

    -L length specified text wrap

    -i directly modify the contents of the file

  Address delimitation way

    1, the direct matching value

      sed -n '5,7'p text file

    2, d ~ step

      sed -n '1 ~ 3p' Text File

    3, $ specified Gyoo

      sed -n '10 ~ $ p 'Text File

    4 / regular /

      sed -n '/ k \ {5, \} /, $ p' Text File

    5、0,addr

      addr can be a digital / $ / regular expression

      sed -n '0, / k, {5 ,,} p' Text File

    6、addr,+N

      Addr addr arranged row after row N

      sed -n '/ fd /, + 5p' Text File

  Common commands

    p print Print

    d delete

    c Replace

      sed "/ aaa / c \ A" Text File

    n N read / add content to the next row pattern matching row in its operating

    w Save the file contents to a new file

    s text Alternatively, a default matching pattern space to replace the contents of the

      Syntax: s / pattern / string /

        Middle / can be replaced by any one of the special character

  sed of advanced applications

    Mode space - hold space

    

Guess you like

Origin www.cnblogs.com/lyali/p/11363551.html