Difference between revisions of "Awk"

From Linuxintro
imported>ThorstenStaerk
(New page: awk is a command for string operations. It allows you to only show the third ''column'' of a file for example. ;Examples: kill all processes of a user ps --no-header -fu <use...)
 
imported>ThorstenStaerk
Line 2: Line 2:
  
 
;Examples:
 
;Examples:
 +
Show only the second column of ''file.txt''
 +
awk '{print $2;}' ''file.txt''
 
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

Revision as of 15:18, 25 July 2009

awk is a command for string operations. It allows you to only show the third column of a file for example.

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