Write a shell script that counts the number of blank lines in a file, count how many lines have a text ‘new’ in it, count how many lines have the last word having a value > 1000

Write a shell script that counts the number of blank lines in a file, count how many lines have a text ‘new’ in it, count how many lines have the last word having a value > 1000

Code:

clear 
echo ---------------------------------- 
echo '\tNumber of lines' 
echo ---------------------------------- 
echo Enter the file name 
read f1 
tl=$(sed -n '$=' $f1) 
echo Total lines in a file is :$tl 
bl=$(grep -c '^$' $f1) 
echo Number of blank lines in a file : $bl 
sl=$(expr $tl - $bl) 
echo Number of text lines in file :$sl 

Output:

---------------------------------- 
Number of lines 
---------------------------------- 
Enter the file name 
t2 
Total lines in a file is :6 
Number of blank lines in a file : 3 
Number of text lines in file :3 

No comments

Powered by Blogger.