1752814 Members
5914 Online
108789 Solutions
New Discussion

Re: find the count

 
SOLVED
Go to solution
Prashant Zanwar_4
Respected Contributor

Re: find the count

YOu can do

filename=yourfilename
cat $filename | sort | uniq >> /tmp/strings.uniq

cat /tmp/strings.uniq | while read line
do
grep -c $line $filename
done

for taking into accoung the blank lines, simply do

grep -c ^$ $filename

Hope above helps

Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Muthukumar_5
Honored Contributor

Re: find the count

Remove blank lines by identfying pattern ^$ and do sort and uniq will give results there.

By simply,

sed 's/^$//g' | sort -nb | uniq -c

-nb used to remove leading blanks and compare them there.

Easy to suggest when don't know about the problem!