shell_Day06

sed command

  Linux text processing Three Musketeers sed
  sed stream EDite
  as a line editor, text editing (editing in units)
  Note: sed to edit the file, but do not change the original file;
 

sed works:

  Specifies a text file, text file sequentially 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, print, edit, save, etc.)
  Usage:
  sed [OPTION] ... {Script-only-IF-NO-OTHER-Script} [the INPUT-File] ...
  sed [parameters] "sed own independent use format statement" [Text File]
  Common Options
    -n reject the default display
    -r specify extended regular expressions
    -e Script for the while IF
    -f specify the script file
    -l length specified text wrap?
    -i directly modify the contents of the file (do not use)
  

Address delimitation way

  1, the direct matching value
    sed -n '5p' file
  2, d ~ step      
    sed -n '1 ~ 3p' file
  3, the end of the specified line $
    sed -n '10, $ p 'document
  4, / regular /
    / Regular 1 /, / n is 2 /
    Sed -n '/ K \ {. 5, \} /, $ P' ABC
  5,0, addr
    addr may be a digital / $ / regular expression
    sed -n '0, / k \ { . 5, \} / P 'ABC
  . 6, addr, N +   
    arranged to addr line after line N addr
    sed -n' / fd /, + 5p 'abc
  ** common commands
    p print print (the default is displayed on the screen) used with the advice and -n;
    replace c
      sed "/ aaa / c \ A" A
    d delete
      sed "/ aaa / d" A
      sed "1, 3D" a
    n-N read / pattern matching is added to the contents of the next row line, and then manipulate
    w save the contents of the file to a new file
      sed "/ patthen / w new file name" name of the original file
      sed "/ k / W / tmp / aabbcc "ABC
    * S * text Alternatively, the default mode is the first alternative to match space;
      syntax: s / pattern / string /
      middle / can be replaced by a special character, for example, any of: s # %%%% @@@ S S ##
    G all
    \ 1 \ 2 and the same packets of regular expressions, implement the reverse application;
    designate a replacement to modify a match
    & preceding call (pattern) matching content
      sed "s /r..t/&er/g "file
    

sed of advanced applications

    Mode space - hold space "occupied space"
    dirname - Remove the file path path portion
    basename - the file name of the file path portion removed

Guess you like

Origin www.cnblogs.com/diyudewudao/p/11408917.html