Back-end Invalid Id Password
Back-end Invalid Id Password
Success
Success
Success
Back-end Invalid Id Password
Back-end User state is invalid
Back-end User state is invalid
Success
Back-end Invalid Id Password
Back-end Invalid Id Password
Success
Balance amount is not enough
User Not found
Back-end Invalid Id Password
Back-end Invalid Id Password
User error
Back-end Invalid Id Password
Back-end Invalid Id Password
Success
Output
9 Back-end Invalid Id Password
2 Back-end User state is invalid
1 Balance amount is not enough
5 Success
1 User Not found
1 User error
I want out put
Back-end Invalid Id Password : 9
Back-end User state is invalid : 2
Balance amount is not enough : 1
Success : 5
User Not found : 1
User error : 1
bash-3.00$
$ awk '{
A[$0]++
}
END {
for( a in A )
printf "%-40s : %5d\n", a, A[a]
}' file1
Back-end User state is invalid : 2
Back-end Invalid Id Password : 9
User Not found : 1
User error : 1
Balance amount is not enough : 1
Success : 6
It's a small modification to preserve the sort order.
#!/bin/ksh
typeset -A ARR
while read line
do
(( ARR["$line"]++ ))
done < Count.log
for k in "${!ARR[@]}"
do
printf "%-40s : %5d\n" "$k" ${ARR["$k"]}
done
This approach will also preserve the order of records:
Back-end Invalid Id Password : 9
Back-end User state is invalid : 2
Balance amount is not enough : 1
Success : 6
User Not found : 1
User error : 1
$ cat Count.log |sort -t 1 | uniq -c | while read CNT LINE; do printf "%40s:%5s\n" "$LINE" "$CNT"; done
Back-end Invalid Id Password: 9
Back-end User state is invalid: 2
Balance amount is not enough: 1
Success: 5
User Not found: 1
User error: 1
Reading your proposal again, and more carefully, I see that you act on the original file, not on the result of all the pipes. That might indeed be most efficient by far.