Grep and awk

What are the difference between grep and awk commands and where can use these in UNIX scripting.

Questions by ramasamba   answers by ramasamba

Showing Answers 1 - 3 of 3 Answers

vipul_se

  • Jan 29th, 2008
 

Grep is a simple pattren searching command. if you want to search some pattren in file or database you can search.But you can not work on the field of a file or some operation on that.
Awk is like sql where you not only have pattern search option but also program action where you can operate on fields of the database and furthur refine your search

eg.gold     1     1986  USA                        American Eagle
     gold     1     1908  Austria-Hungary     Franz Josef 100 Korona
     silver  10    1981  USA                         ingot
     gold     1     1984  Switzerland            ingot
   
by command <awk '/gold/' coins.txt> we find the lines that contain the string "gold"
the same result can be obtained by grep and find command.
But if you want the data with date <1980 then grep will not be of furthur use...
awk can easily give you the result by command.

<awk '{if ($3 < 1980) print $3, "    ",$5,$6,$7,$8}' coins.txt >
it gives output
1908    Franz Josef 100 Korona

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions