2

I would like to count the copies of each line in a txt file and I have tried so many things until know, but none worked well. In my case the text has just a word in each line.

This was my last try

echo -n 'enter file for edit: '
read file
for line in $file ; do
echo  'grep -w $line $file'
done; <$file

For example:

input file

a
a
a
c
c

Output file

a 3
c 2

Thanks in advance.

pilcrow
  • 56,591
  • 13
  • 94
  • 135
m_papas
  • 91
  • 1
  • 12

1 Answers1

1
$ sort < $file | uniq -c | awk '{print $2 " " $1}'
pilcrow
  • 56,591
  • 13
  • 94
  • 135