sed, awk regular expression

sedTake good lines, awkcommand good at taking column

and

  • Format :sed <option> <script> <file>

  • option

    • -e: Execute multiple commands
      • The command must be separated by a semicolon
      • No space between the end of the command and the semicolon
      • example:sed -e 's/brown/green; s/dog/cat' data.txt
    • -f: Read commands from a file
      • Each command line without the semicolon
      • example:sed -f script.sed data.txt
    • -n: No command output, print output command to complete
  • script

    • ** s **: replacement string between the first string between the second slash slash
      • example:echo "a dog" | sed 's/dog/cat/'
  • file

    • Not specified defaults to STDIN
  • sed does not modify file data, but to send the modified data to STDOUT

awk

  • Format :awk <options> <program> <file>

  • option

    • -f: Read commands from a file
      • Must {}beginning of the end
      • Each command line without the semicolon
    • -F: Custom field delimiter
      • The default delimiter is whitespace
      • example:awk -F: '{print $1}' /etc/passwd
  • program

    • You can customize variables
      • You do not need a custom variable references$
      • The default variable
        • $0On behalf of the entire line of text
        • $11 represents the first data field
        • $nN represents the data fields
    • Keyword
      • BEGIN: Script execution defined later in the pre-processing of data
        • Two single quotes in the command remains the same
        • example:awk 'BEGIN {print "hello world!"} {print $0}'
      • END: After the definition of the script execution in the data processing
    • Semicolon between commands can execute a plurality of commands
      • example:echo "Hello World" | awk '{$2="golang"; print $0}'
  • file

    • Not specified defaults to STDIN

    Regular Expressions

Published 161 original articles · won praise 19 · views 50000 +

Guess you like

Origin blog.csdn.net/winter_wu_1998/article/details/104089802