Longest line

Write A Shell Script To Find The Longest line In A Given File Shell Script: clear l=`cat me.txt | wc -l` echo "Content of the file:" cat me.txt echo long=`cat me.txt|head -1|wc -c` x=1 for((i=2;i<=$l;i++)) do str=`cat me.txt | head -$i | tail -1` w=`echo $str | wc -c` if [ $w -gt $long ] then long=$w x=$i fi done cat me.txt|head -$x|tail -1 OUTPUT: [admin@localhost ~]$ sh longestline.sh Content of the file: i am xyz i read in vit computer science department i kk xyz is my name i am xyz xyz xyz xyz xyx xyz computer science department i kk

Share:

0 comments