Difference between revisions of "Awk"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 1: Line 1:
[[awk]] is a [[command]] for string operations. It allows you to only show the third ''column'' of a file for example.
+
[[awk]] is a [[command]] for string operations. It allows you to only show the third ''column'' of a file for example. awk is not a simple command, but rather a programming language on its own. awk and gawk, its GNU implementation, are used synonymously.
  
 
;Examples:
 
;Examples:
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
 +
 +
= See also =
 +
* [http://man-wiki.net/index.php/Awk gawk man page]

Revision as of 15:22, 25 July 2009

awk is a command for string operations. It allows you to only show the third column of a file for example. awk is not a simple command, but rather a programming language on its own. awk and gawk, its GNU implementation, 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

See also