Difference between revisions of "Awk"
From Linuxintro
imported>ThorstenStaerk |
imported>ThorstenStaerk |
||
Line 6: | Line 6: | ||
kill all processes of a user | kill all processes of a user | ||
[[ps]] --no-header -fu <username> | [[awk]] '{ print $2 }' | [[grep]] -v $$ | [[xargs]] kill | [[ps]] --no-header -fu <username> | [[awk]] '{ print $2 }' | [[grep]] -v $$ | [[xargs]] kill | ||
− | extract MAC address from ifconfig output | + | extract eth0's MAC address from ifconfig output |
ifconfig | grep eth0 | awk '{ print $5 }' | ifconfig | grep eth0 | awk '{ print $5 }' | ||
= See also = | = See also = | ||
* [http://man-wiki.net/index.php/Awk gawk man page] | * [http://man-wiki.net/index.php/Awk gawk man page] |
Revision as of 16:06, 26 March 2010
awk is a command for string operations. For example, it allows you to show only the second column of a file. awk is not a simple command, but rather a programming language on its own. awk and gawk (for GNU awk) are used synonymously.
- Examples
Show only the second column of file.txt
awk '{print $2;}' file.txt
kill all processes of a user
ps --no-header -fu <username> | awk '{ print $2 }' | grep -v $$ | xargs kill
extract eth0's MAC address from ifconfig output
ifconfig | grep eth0 | awk '{ print $5 }'