How to count duplicate the lines of a file by using Linux Shell Programming?


Hi,

I’m new to linux and to shell programming. I have an assignment to create a shell script that shows all the folders, sub folders and files of the current directory. LS does this. But I must count how many duplicate lines each file has, and show the line that is repeated the most times in each file.

I really have no idea where to start. How can I read/compare lines within a file?

Thanks in advance!

One Response to “How to count duplicate the lines of a file by using Linux Shell Programming?”

  • Mech:

    grep . anyFile | sort | uniq | wc
    grep . anyFile | sort | wc

    If a line is repeated, the output of the top grep code will be less than the bottom one.

Leave a Reply