Difference between revisions of "AWK Command"
Jump to navigation
Jump to search
| Line 13: | Line 13: | ||
awk '{print NR "- " $1}' filename.txt | awk '{print NR "- " $1}' filename.txt | ||
// adds a - between columns | // adds a - between columns | ||
'''search log file ''' | |||
cat /var/log/apache2/access.log | grep -i 'ads.outwaterads.com' | awk '{print $1, $2,$3,$4, $6,$7}' | |||
Revision as of 16:22, 26 April 2022
Print file
awk '{print}' filename.txt
Find text in file
awk '/bug/ {print}' filename.txt
Print certain columns
awk '{print $1,$2}' filename.txt
Print out line numbers
awk '{print NR, $0}' filename.txt
awk '{print $1, $NF}' filename.txt
// $0 prints the entire line
// NR prints the line number
// NF prints the last field of the file
awk '{print NR "- " $1}' filename.txt
// adds a - between columns
search log file
cat /var/log/apache2/access.log | grep -i 'ads.outwaterads.com' | awk '{print $1, $2,$3,$4, $6,$7}'