Awk Script PDF
Awk Script PDF
Write A Shell Script To Find Out The Unique Words In A File And Also Count The Occurrence Of Each Of These
ords.
Note: It may possile each Line Has Multiple Words.
Solution:
Assume File:
cat animal.txt
tiger bear
elephant tiger bear
bear
Question 2:
Write A Shell Script To Get The Total Count Of The Word “Linux” In All The “.Txt” Files And Also Across Files
resent In Subdirectories.
Solution:
$ find . -name *.txt -exec grep -c Linux '{}' \; | awk '{x+=$0;}END{print x}'
_____________________________________________________________________________________________
_______________________________________________________
To complete further Questions, create test.txt file with below texts:
test.txt
one two three four five six
John 246810 team01 UK Birmingham FTE
Paul 135790 team02 UK Glasgow FTE
Marcus 049583 team03 DE Bremen PTE
Foxy 903485 team01 UK Aston PTE
BEGIN {
print "--- I am a test awk file ---"
count=0
}
{
if ($3 =="team01") {
print "team01 members found: "$1,"-",$3
count=count+1
}
}
END {
print "------------------------------"
printf("\tTotal Number of Records Processed:\t%d\n", NR)
printf("\tNumber of team01 members found :\t%d\n", count)
}
Question 8:
awk '
> BEGIN { print "Analysis of \"li\"" }
> /li/ { ++n }
> END { print "\"li\" appears in", n, "records." }' mail-list
END {
for (i = 1; i <= count; i++)
print lines[i]
}