Sunday, November 13, 2005

AWK - Find - Delete Second Field/Column - One Liner 25 - 26

AWK


awk '/PATTERN/ {print "PATTERN FOUND"}' /var/awk_programming_test


This programming one liner allows you to search for PATTERN in awk_programming_test file. Once the pattern is found, the print statement is invoked .




AWK - Delete second column


Programming One Liner 26

awk ' BEGIN{FS=",";} { $2= ""; print}' /var/awk_programming_test


This programming one liner allows you to delete the second field in the specified CSV and the results are displayed on the screen. If the file /var/awk_programming_test had the following contents:



redhat,linux web server
fedora,linux web server
xp,windows dedicated server
windows 98,windows dedicated server
solaris,sun web server



Then invoking the one liner # 26 will produce the following results


redhat
fedora
xp
windows 98
solaris




Programming "One Liner" lookup terms:
awk





USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external , , and blogs.

1 comment:

Anonymous said...

actually this doesn't delete second field, but makes it blank:

$ echo "one,two,three" | awk 'BEGIN{FS=",";OFS=",";}{$2=""; print $0;}'
one,,three
$

--
Atti