I want count of number of records to be printed on each row.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I want count of number of records to be printed on each row.
# 1  
Old 11-02-2015
I want count of number of records to be printed on each row.

we want the count of number of records to be printed on each row.
For Ex:

if there are 5 records on one unique id , the count "5'' should be printed on each record in other column. Please help for this. I am using unix & Cygwin.
Below are sample records:
Code:
KCZ0650473 	9640898576	29-07-14	EESHVARAMMA  TOTADA 	
KCZ0650473 	9542742485	20-05-14	EESHWARAMMA  TOTADA 	 
KCZ0650473 	9542568725	20-05-14	EESHWARAMMA  TOTADA 	
KCZ0650473 	8466815506	12-10-13	ESWARAMMA    THOTADA 	
KCZ0650473 	8465942075	25-09-13	ESHVARAMMA   TOTADA 	
KCZ0650473 	8096056237	07-06-14	EESHVARAMMA  TOTADA 	 
KCZ0650473 	7660874881	25-12-13	EESHVARAMMA  TOTADA 	 
KCZ0650473 	7036175851	30-09-14	EESWARAMMA   TOTADA 	
LQM1848506 	9948258707	09-05-15	RAMA KRISHNA TIRUMANI 	
LQM1848506 	9912283897	08-05-15	RAMAKRISHNA  TIRIRUMANI 	
LQM1848506 	9912283867	09-05-15	RAMAKRISHNA  TIURMANI 	
LQM1848506 	9704647089	31-10-13	RAMAKRISHNA  TIRUMANI 	
LQM1848506 	9553889842	28-01-14	RAMA KRISHNA TIRUMANI 	
LQM1848506 	9542543464	06-03-14	RAMA KRISHNA TIRUMANI 	
LQM1848506 	7730838559	27-03-15	RAMAKRISHNA  TIRUMANI 	
LQM1848506 	7729868778	27-03-15	RAMAKRISHNA  TIRUMANI 	 
RGM0751099 	9951725477	18-03-15	ASHOK KUMAR  ANJINAPPA GARI 	
RGM0751099 	9951392653	18-03-15	ANJINAPPA ASHOK KUMAR  . 	
RGM0751099 	9666048729	26-03-15	ANJINAPPA GARI ASHOK KUMAR	
RGM0751099 	9505728685	08-01-15	ANJINAPPA GARI ASHOK KUMAR	 
RGM0751099 	8125249248	14-10-14	ASHOK KUMAR  ANJINAPPAGARI 	 
RGM0751099 	7842729360	12-12-13	ASHOK KUMAR  ANJINAPPA GARI 	
RGM0751099 	7095906292	29-12-14	ASHOK KUMAR  ANJINAPPA GARI 	 
RGM0751099 	7095128680	03-12-14	ASHOK KUMAR	ANJINAPPAGARI

Rajesh

Last edited by Don Cragun; 11-02-2015 at 03:02 AM.. Reason: Add CODE tags.
# 2  
Old 11-02-2015
Quote:
Originally Posted by ElijaRajesh
we want the count of number of records to be printed on each row.
For Ex:

if there are 5 records on one unique id , the count "5'' should be printed on each record in other column. Please help for this. I am using unix & Cygwin.
Below are sample records:
KCZ0650473 9640898576 29-07-14 EESHVARAMMA TOTADA
KCZ0650473 9542742485 20-05-14 EESHWARAMMA TOTADA
KCZ0650473 9542568725 20-05-14 EESHWARAMMA TOTADA
KCZ0650473 8466815506 12-10-13 ESWARAMMA THOTADA
KCZ0650473 8465942075 25-09-13 ESHVARAMMA TOTADA
KCZ0650473 8096056237 07-06-14 EESHVARAMMA TOTADA
KCZ0650473 7660874881 25-12-13 EESHVARAMMA TOTADA
KCZ0650473 7036175851 30-09-14 EESWARAMMA TOTADA
LQM1848506 9948258707 09-05-15 RAMA KRISHNA TIRUMANI
LQM1848506 9912283897 08-05-15 RAMAKRISHNA TIRIRUMANI
LQM1848506 9912283867 09-05-15 RAMAKRISHNA TIURMANI
LQM1848506 9704647089 31-10-13 RAMAKRISHNA TIRUMANI
LQM1848506 9553889842 28-01-14 RAMA KRISHNA TIRUMANI
LQM1848506 9542543464 06-03-14 RAMA KRISHNA TIRUMANI
LQM1848506 7730838559 27-03-15 RAMAKRISHNA TIRUMANI
LQM1848506 7729868778 27-03-15 RAMAKRISHNA TIRUMANI
RGM0751099 9951725477 18-03-15 ASHOK KUMAR ANJINAPPA GARI
RGM0751099 9951392653 18-03-15 ANJINAPPA ASHOK KUMAR .
RGM0751099 9666048729 26-03-15 ANJINAPPA GARI ASHOK KUMAR
RGM0751099 9505728685 08-01-15 ANJINAPPA GARI ASHOK KUMAR
RGM0751099 8125249248 14-10-14 ASHOK KUMAR ANJINAPPAGARI
RGM0751099 7842729360 12-12-13 ASHOK KUMAR ANJINAPPA GARI
RGM0751099 7095906292 29-12-14 ASHOK KUMAR ANJINAPPA GARI
RGM0751099 7095128680 03-12-14 ASHOK KUMAR ANJINAPPAGARI
Rajesh

Please try this:

Code:
awk '
{
  for (i=1; i<=NR; i++)
{ 
print $0 " " NF
}
}' unix.txt

# 3  
Old 11-02-2015
Now that CODE tags have been added to your post, we can see that, except for the last line, each line has four fields separated by a <space> and a <tab> (between the 1st two fields) and just separated by a <tab> (between the 2nd and 3rd field and between the 3rd and 4th field). The last line has an additional <tab> separated field.

You have not given us any indication of which field (or combination of fields) constitutes the unique id that you're trying to count. You have not described whether you just want to print the unique ids and the counts or if you want to print the original input with an additional field with an added count field. (And, if it is the latter, we don't know if you want a running count of the number of times that unique id has appeared in the file to that point or if you want each line to have the number of times the unique id on that line appears anywhere in the file.)
  1. Please use CODE tags when displaying sample input, sample output, and code segments.
  2. Please tell us which UNIX operating system (or operating systems) you are using in addition to using Cygwin on a Windows operating system.
  3. Please tell us if your input file(s) are UNIX/Linux format text files or DOS/Windows format text file?
  4. Please explain what in your input file(s) is the unique id.
  5. Please explain clearly what output you are trying to produce.
  6. Please show us the output you are hoping to produce from the sample input you provided in post #1 in this thread.
  7. Please tell us what shell you are using.
  8. Please show us the code that you have written to try to solve this problem.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reseting row count every given number of rows

I have a file with 48 rows. I am counting 6 rows and adding 6 to that number and repeating the operation, and then output the value in column 1. For the second column, I would like to get sort of a binary output (1s and 2s) every 3rd row. This is what I have: awk '{print ++src +... (1 Reply)
Discussion started by: Xterra
1 Replies

2. Shell Programming and Scripting

How to get row data printed in column using awk?

Hi team, I have below sample file. $ cat sample dn: MSISDN=400512345677,dc=msisdn,ou=NPSD,serv=CSPS,ou=servCommonData,dc=stc structuralObjectClass: NphData objectClass: NphData objectClass: MSISDN entryDS: 0 nodeId: 35 createTimestamp: 20170216121047Z modifyTimestamp: 20170216121047Z... (3 Replies)
Discussion started by: shanul karim
3 Replies

3. Shell Programming and Scripting

Use GREP to count number of records and place it in a variable

I am trying to count the number of records from different files using grep, and then place the result in a separate variable for each file, so at the end of my shell script, I can sum all the variables and check if the number of records are equal to what I was expecting. It is weird butwc -ldoes... (2 Replies)
Discussion started by: dhruuv369
2 Replies

4. Solaris

[solved] lpstat count how many time printed

Hi guys! i've made a little mysql database to count how many time we print/day from a solaris server. To get to this info i use the command: lpstat -W completed|grep "date"after a few dates i've noticed that the amount of printout was everytime 500?! now the lpstat command keeps only the last... (0 Replies)
Discussion started by: beta17
0 Replies

5. Shell Programming and Scripting

Counting number of records with string row delimiter

HI, i have a file like this t.txt f1|_f2|_ f1|_f2|_ f1|_f2|_ as if col delimiter is |_ and row delimiter |_\n trying to count number of records using awk $ awk 'BEGIN{FS="|_" ; RS="~~\n"} {n++}END{print n} ' t.txt 7 wondering how can i count this to 3 ? thx (9 Replies)
Discussion started by: aksforum
9 Replies

6. Shell Programming and Scripting

Count the number or row with same value in a column

This is the source file, we called it errorlist.out 196 server_a server_unix_2 CD 196 server_b server_win_1 CD 196 server_c server_win_2 CD 196 server_bd server_unix_2 CD 196 server_d server_unix_2 CD 196 server_es server_win_1 CD 196 ... (14 Replies)
Discussion started by: sQew
14 Replies

7. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

8. Shell Programming and Scripting

count number of nonempty columns in row

Hi, Suppose i have a inputfile in csv format. How to use awk to count 'the number of nonempty columns in each row' minus one, and add the value as a new column in the end For cosmetic reason, it's even better to include a descriptive label for the last column in the first row. for... (2 Replies)
Discussion started by: grossgermany
2 Replies

9. UNIX for Dummies Questions & Answers

row count but only number part

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question