MS06
June 7, 2016, 1:30am
1
Hi,
I have a .dat file with contents like the below:
Input file
============SEQ NO-1: COLUMN1==========
9835619
7152815
============SEQ NO-2: COLUMN2 ==========
7615348
7015548
9373086
============SEQ NO-3: COLUMN3===========
9373086
Expected Output: (I just need the total distinct count of records under a separate header-as like below)
============SEQ NO-1: COLUMN1==========
2
============SEQ NO-2: COLUMN2 ==========
3
============SEQ NO-3: COLUMN3===========
1
Please help me with the unix command for the same.
Hello MS06,
Welcome to forums, request you to please use code tags as per forum rules for commands/codes/Inputs which you are using into your posts. For your requirement, could you please try following.
awk '/^==/{if(count){print count;count=""};print;next} {count++} END{print count}' Input_file
OR
awk '/^==/{if(count){print count;count=""};print;next} !/^$/{count++} END{print count}' Input_file
Second solution will leave all empty lines and will not count them. So output will be as follows.
============SEQ NO-1: COLUMN1==========
2
============SEQ NO-2: COLUMN2 ==========
3
============SEQ NO-3: COLUMN3===========
1
Thanks,
R. Singh