Showing posts with label unix shell scripting. Show all posts
Showing posts with label unix shell scripting. Show all posts

Thursday, January 12, 2012

Unix shell scripting


Print last field of the text file.
==================================
ux238 (2):/u02/home/satheesh> cat test.txt
satheesh kumar Bala Mani
kumar satheesh kiruthika
meena satheesh i
ux238 (0):/u02/home/satheesh> awk '{print $NF}' test.txt
Mani
kiruthika
i

Here 'NF' <-- Number of fields.

Try this
-------
awk -F'i' '{print $NF}' test.txt
cut -d':' -f1 test.txt

 Count the number of occurence of perticular word from file
 ==========================================================
 awk '{for (i=1;i<=NF;i++)if ( $i == "kumar")c++}END{print c}' test.txt