AWK: Difference between revisions

146 bytes added ,  4 years ago
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 3:
<br />
 
= Basics =
Usage:
cat stats_collection.log | grep svmem | awk '{print $1 $2," - ",$7}'
 
Source: [https://www.geeksforgeeks.org/awk-command-unixlinux-examples/ geeksforgeeks.org]
 
* Awk is a scripting language used for manipulating data and generating reports.
= Built In Variables =
* Field variables — $1, $2, $3,
 
* Awk’s built-in variables include the field variables—$1, $2, $3,
* $0 is the entire line.
* Usage:
cat stats_collection.log | grep svmem | awk '{print $1 " " $2," - ",$7}'
 
= Built In Variables =
 
* NR: current count of the number of lines.
Line 27 ⟶ 30:
 
* To find/check for any string in any column:
awk '{ if($3 == "B6") print $0;}' geeksforgeeksemployee.txt
 
* Print lines with more than 10 characters: