End of each line count the values in the file

Hi,

How to find the end of character in the file.
My requirement should be as below.1 is repeating 1 time ,2 is repeating 3 times...

 type 1: 1 
type 2: 3 
type 3: 2
9f680177|20077337258|0|0|0|1000004647916|1
9f680177|20077337258|0|0|0|1000004647916|2
9f680177  20077337258 0 0 0 1000004647916|2
9f680177  20077337258 0 0 0 1000004647916|2
9f680176|20077337258|0|0|0|1000004647916|3
9f680175|20077337258|0|0|0|1000004647916|3 

Thanks...

The third and fourth line have different field separators, is that correct?

perl -F'|' -lane '$x{$F[-1]}++; END {print "$_ -> $x{$_}" for(sort keys %x)}' inputfile

Hi

$ awk -F"|" '{a[$NF]++;}END{for(i in a)print "Type "i":", a;}' file
Type 1: 1
Type 2: 3
Type 3: 2

Guru.

Well, the regexp for the last character in a line is:

.$

Therefore:

sed 's/.*\(.\)$/\1$/' /your/file | sort -u > tempfile

This gives you all the last characters, uniquely, plus a "$", which will constitute the regexp for exactly this character. You now use this tempfile as input for "grep" with the "-c" (count) option:

grep -c -f tempfile /your/file

I hope this helps.

bakunin

@Scrutinizer, Filed seperator not an issues... irresptive delemeter...

Thank balajesuri,now it is working fine...i have to include the in unix script...

---------- Post updated at 05:25 AM ---------- Previous update was at 05:19 AM ----------

Thanks...Guru...if i use your command output coming like this.

Type : 4
Type 8: 3
Type 1: 1
Type 2: 2
Type 3: 1

i don't wan't Type : 4