End of each line count the values in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting End of each line count the values in the file
# 1  
Old 06-01-2012
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...
Code:
 type 1: 1 
type 2: 3 
type 3: 2

Code:
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...
# 2  
Old 06-01-2012
The third and fourth line have different field separators, is that correct?
# 3  
Old 06-01-2012
Code:
perl -F'|' -lane '$x{$F[-1]}++; END {print "$_ -> $x{$_}" for(sort keys %x)}' inputfile

# 4  
Old 06-01-2012
Hi



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


Guru.
# 5  
Old 06-01-2012
Well, the regexp for the last character in a line is:

Code:
.$

Therefore:

Code:
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:

Code:
grep -c -f tempfile /your/file

I hope this helps.

bakunin
# 6  
Old 06-01-2012
@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.

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

i don't wan't Type : 4
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to extract values and print at end of each line

In the below perl I am trying to extract and print the values AF1=, the GT value, and F or QUAL diveded by 33 (rounded to the nearest whole #). The GT value is at the end after the GT:PL so all the possibilities are read into a hash h, then depending on the value that is in the line the... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

How to append word count at end of file?

Hi guys, I have to append the word count of a file at the end of the file name like this - > "filename_2345" where 2345 is the word count of "filename". How do i achieve this using one command ? I am not allowed to store the word count in a variable and then concatenate. Request your... (1 Reply)
Discussion started by: peter2312
1 Replies

3. Shell Programming and Scripting

Count the field values in a file

Hi I have a file with contents like : 101,6789556897,0000795369 - seq - fmt_recs187] - avg_recs 101,4678354769,0000835783 - seq - fmt_recs98] - avg_recs 221,5679787008,0001344589 - seq - fmt_recs1283] - avg_recs I need to find the sum of the all the values (which are in bold). here... (6 Replies)
Discussion started by: rkrish
6 Replies

4. Shell Programming and Scripting

awk to count start and end keyword in a line

Hello fellow awkers and seders: need to figure out a way to ensure a software deployment has completed by checking its trace file in which I can store the deployment results as follows: echo $testvar ===== Summary - Deploy Result - Start ===== ===== Summary - Deploy Result - End =====... (1 Reply)
Discussion started by: ux4me
1 Replies

5. Shell Programming and Scripting

Get the sum of values in between begin and end in the file

Hi All, test file Begin Script Run at Thu Mar 14 09:24:16 PDT 2013 tst_accounts: ws zip: WS_out_20130313.tar.gz dat: test_20130313.dat count: 63574 loaded: xx pre-merge: xx post-merge: xx timestamp: Thu Mar 14 09:30:42 PDT 2013 tst_accounts: ws zip: WS_out_20130313.tar.gz dat: s_20130313.dat... (6 Replies)
Discussion started by: bmk
6 Replies

6. Shell Programming and Scripting

Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below. Detail Id Info Id Order Id STATUS Status Date FileDetail 99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM... (7 Replies)
Discussion started by: dvrbabu
7 Replies

7. Shell Programming and Scripting

How to count Unique Values from a file.

Hi I have the following info in a file - <Cell id="25D"/> <Cell id="26A"/> <Cell id="26B"/> <Cell id="26C"/> <Cell id="27A"/> <Cell id="27B"/> <Cell id="27C"/> <Cell id="28A"/> I would like to know how would you go about counting all... (4 Replies)
Discussion started by: Prega
4 Replies

8. Shell Programming and Scripting

How to put count for first element in a file at the end

Hi, I have a file where I need to count the total for the first element and put it back at the end of file... here is the example... input.. FHDR|ABC|20100607| |ABC|8453|CDE|E166|||| 123|ABC|8453|CDE|E166|||| 123|ABC|8453|CDE|E166|||| 111|ABC|8453|CDE|E166||||... (8 Replies)
Discussion started by: donadarsh
8 Replies

9. Shell Programming and Scripting

Remove end of values in file

leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>more pmonfile.dat entp_stdby ot1p_stdby lawp_stdby I am wonder how to remove the _stdby from all the values in this dat file using #!/bin/ksh Thanks! (4 Replies)
Discussion started by: LRoberts
4 Replies

10. Shell Programming and Scripting

Line Count and Append it to the end of the file.

Hi, I want to get a Line count of a file and append that at the end of the file. The Line count should not include the Headers : ------------------ COL1,COL2,COL3 123,abc,011 111,abd,0212 Record Count: 2 ------------------- Thanks. (7 Replies)
Discussion started by: smc3
7 Replies
Login or Register to Ask a Question