User Tools

Site Tools


awk

Warning: Undefined variable $html in /usr/share/nginx/html/lib/plugins/tabinclude/helper.php on line 240

AWK

  • Basic awk
  • sed

The following prints all lines in the file specified. You can also replace $0 with nothing.

awk '{ print $0 }'
The following will only print the first column in the file. The -F is the field seperator and is specified with: -F“:”
awk -F":" '{ print $1 }' /etc/passwd

You can also select multiple columns and separate them with a space for a better format
awk -F":" '{ print $1 " " $2 }' /etc/passwd
Grab every instance where column is greater than 4
sar -q | awk '$4 >= 4'
Awk for multiple words
awk '/Luke|Joe/' test
Awk for multiple words case insensitive:
awk '/Luke|Joe/i' test
awk inversely
awk '!/Luke/' test


| awk '$5 ~ /[0-9]w/'
| awk '$5 ~ /[0-9]w/ && $6 ~ /REG/'

awk.txt · Last modified: 2024/05/23 07:26 by 127.0.0.1