
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.93 KB | hits: 8 | expires: Never
Count the occurrence of a string in an input file
#!/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
/./
sort -f FILE | uniq -ic
s/^ *([0-9]+) (.*)/2 appears 1 times/
while read line
do
uc=$(echo $line | tr [a-z] [A-Z] | tr -d ' ')
echo $uc $(grep -i "$uc" strs.txt | wc -l)
done< data.txt | sort | uniq
31
ALLEN 6
MARK 4
MOKADDIM 1
SHIPLU 1
TIM 4
sort -f data.txt | uniq -i -c | while read num word
do
echo $(echo $word|tr [a-z] [A-Z]) appeard $num times
done