Count number of lines between a pattern in a large file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Count number of lines between a pattern in a large file
# 1  
Old 05-21-2013
RedHat Count number of lines between a pattern in a large file

1000CUS E Y4NYRETAIL
10010004HELIOPOLIS
110000500022360591000056XX EG
1101DEBY XXAD ZSSKY TSSROS
1102HANYNNYY@HOTMAIL.COM
210030/05/201301/06/2013AED
3100 OPE
3100 CLO
3100 The
1000CUS E Y NYCORPORATE
10010004HELIOPOLIS
110000500025270504550203XX EG
1101XXXQ FOR CTING AND GFDGSSS
1102
210030/11/201230/05/2013EUR
3100 OPE
3100
1000CUS E Y NYCORPORATE

I have a large file in the above format. I want loop through the file and generate a report with two columns as shown in the image attached.

HTML Code:
<table border="1">
<tr>
<th>COLUMN1</th>
<th>COMMENTS1</th>
<th>COLUMN2</th>
<th>COMMENTS2</th>
</tr>
<tr>
<td>059100005613</td>
<td>the number appearing at position 15 on the line begining with 1100</td>
<td>8</td>
<td>No of lines between 1st identifier 1000CUS and 2nd identifier 1000CUS</td>
</tr>
<tr>
<td>050455020305</td>
<td>the number appearing at position 15 on the line begining with 1100</td>
<td>7</td>
<td>No of lines between 2nd identifier 1000CUS and 3rd identifier 1000CUS</td>
</tr>
</table> 
and so on...

The below command is returning 8, which I think I will need to put in a loop. The one that i'm finding difficul to extract is the information at position 15 on the line begining with 1100.

awk '/1000CUS/&&!f{f=1;next;}/1000CUS/&&f{print x;exit;}f{x++}'

Any pointers would be of great help.

Thanks
Joe
Count number of lines between a pattern in a large file-sample_outputpng
# 2  
Old 05-21-2013
Your requirement is really vague!

But I noticed that you are struggling to extract data from specific position. Then have a look at awk substr function:

Refer: String Functions
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find count total number of pattern in a file …?

How to find count total number of pattern in a file … File contains : a.txt ------------- aaa bbb nnn ccc aaa bbb aaa ddd aaa aaa aaa aaa grep -c aaa a.txt Op: 4 ( But my requirement is should count the total no of patterns as 7 ) (4 Replies)
Discussion started by: Jitten
4 Replies

2. Shell Programming and Scripting

Count number of free lines in a text file

Hi Everybody I want to write a script to count the number of lines in a file that don't ahve any thing on it, the free lines, i try to do it with fgrep "" which means to grep on the spaces but it does not work. help me please? (3 Replies)
Discussion started by: hard_revenge
3 Replies

3. Shell Programming and Scripting

Parse large file on line count (random lines)

I have a file that needs to be parsed into multiple files every time there line contains a number 1. the problem i face is the lines are random and the file size is random. an example is that on line 4, 65, 187, 202 & 209 are number 1's so there has to be file breaks between all those to create 4... (6 Replies)
Discussion started by: darbs121
6 Replies

4. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

5. Shell Programming and Scripting

Count the number of lines in a file with one condition

Hi Everyone, 1.txt Mon 08 Feb 2010 12:30:44 AM MYT;1265560244;e164:0000116047275464;T;Central;0; Mon 08 Feb 2010 12:30:46 AM MYT;1265560246;e164:0000116047275464;T;Central;0; Mon 08 Feb 2010 12:30:48 AM MYT;1265560248;e164:0000116047275464;T;Central;0; Mon 08 Feb 2010 12:30:50 AM... (1 Reply)
Discussion started by: jimmy_y
1 Replies

6. Shell Programming and Scripting

Count the number of occurrences of a pattern between each occurrence of a different pattern

I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'. Here's a portion of the text I'm trying to parse: lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb registrations: key 4156 4353 0000 0000 ... (3 Replies)
Discussion started by: slipstream
3 Replies

7. UNIX for Dummies Questions & Answers

Count of Number of Lines in a File

Dear Members, I want to count the number of lines in a file; for that i am using the following command : FILE_LINE_COUNT=`wc -l $INT_IN/$RAW_FILE_NAME` if i do an echo on FILE_LINE_COUNT then i get 241 /home/data/testfile.txt I don't want the directory path to be displayed. Variable... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

8. Programming

to count the number of commented lines in a file

can someone guide me how to have a C pgm to count the number of commented lines? (3 Replies)
Discussion started by: naan
3 Replies

9. Shell Programming and Scripting

nawk-how count the number of occurances of a pattern, when don't know the pattern

I've written a script to count the total size of SAN storage LUNs, and also display the LUN sizes. From server to server, the LUNs sizes differ. What I want to do is count the occurances as they occur and change. These are the LUN sizes: 49.95 49.95 49.95 49.95 49.95 49.95 49.95 49.95... (2 Replies)
Discussion started by: cyber111
2 Replies

10. Shell Programming and Scripting

Count number of lines in Binary file

Hi Friends Please help me out to count number of lines in binary file. It gives some wrong(less) using wc -l. Is there any other way to count lines of binary file. Thanks. (3 Replies)
Discussion started by: vanand420
3 Replies
Login or Register to Ask a Question