Pages

Ads 468x60px

Monday, July 23, 2012

Linux: AWK Script (Pattern Processing Language)

This will give you little idea about AWK Script


1.  Write an AWK program that numbers each line in a file and sends its output to standard output.
Ans. gawk ‘{print NR, $0}’


2.  Write an AWK program that displays the number of characters in the first field followed by the first
field and sends its output to standard output.
Ans. gawk ‘{print length($1), $1}’


3.  Use AWK to determine how many lines in /usr/share/dict/words contain the string abul. Verify your
answer using grep.
Ans. BEGIN { total =0}
        /abul/ {total ++}
        END {print total}


4.  Using AWK, count the number of lines in a file.
Ans. BEGIN { total =0}
        {total ++}
        END {print total}
        or
        END {print NR}




No comments:

Post a Comment