There is a shell script that should process the incoming text file.
This text file contains lines divided into several lines, and each line is present more than once.
The shell script should read this text file and output a line and the amount of each line.
Consider a text file:
Tim
tim
Mark
Mark
Allen
ALLen
ALLEN
The output should be like this:
Tim appears 2 times
The icon appears 2 times
Allen appears 3 times
Now I can print the appearance of the lines, but this is repeated the number of times the line occurs, that is, "Tim appears 2 times" is printed twice. I tried to replace the NULL string as soon as I count its appearance, but for some reason sed is not working, maybe I am not calling it in the right place (or correctly)
#!/bin/bash INPUT_FILE="$1" declare -a LIST_CHARS if [ $# -ne 1 ] then echo "Usage: $0 <file_name>" exit 1 fi if [ ! -f $INPUT_FILE ] then echo "$INPUT_FILE does not exists. Please specify correct file name" exit 2 fi while read line do while read i do echo $line count=`grep -i $line | wc -l` echo "String $line appears $count times" done < $INPUT_FILE done < $INPUT_FILE
source share