Cutting rows after a selected point

I have a log file from which I want to cut out the ten lines assoictiated to my search requirment (cust_ref #).

The cust_ref number will be on te first line and the update information will be on the following ten lines (which dosen't linking data to grep on).

Using a script I would like to search to the cust_ref and cut the 11 lines I need.

Columns, characters I can cut but don't know where to start on cutting whole lines!!!! :rolleyes:

Any usefull tips?

Any Fanks,

Neil

Hi,

Can you give an example of the file format?

Cheers
Helen

This is an example, would take too longto remove customer details.

2003-09-04 12:20:00 INFO [CUST_REF ] blah blah
2003-09-04 12:20:00 INFO [ John ] blah blah
2003-09-04 12:20:00 INFO [ Doe ] bah blah blah
2003-09-04 12:20:00 INFO [ Gender ]
2003-09-04 12:20:00 INFO [ DOB ]
2003-09-04 12:20:00 INFO [ Postal code ]
2003-09-04 12:20:00 INFO [ Limit 100 ] blah blah
2003-09-04 12:20:00 INFO [ API Value ]
2003-09-04 12:20:00 ERROR [ Error Element ]
2003-09-04 12:20:00 INFO [ Record num ]
2003-09-04 12:20:00 INFO [ status ]
several line of mixed information lines before the next lot of details.

Each lot of details in the square brackets will be different, the x number lines after the CUST_REF will be for that customer. The date/time stirng is not an option because you get more than one customer load in the same second and I don't nesacery want all customers. Just the ones I specify.

Try this:

sed -n '/CUST_REF/{N;N;N;N;N;N;N;N;N;N;p;}' < your_file

I like oombera's sed solution, but I wouldn't have chosen sed because it's a bit mysterious to me. Here's an awk solution.

awk '/CUST_REF/ { i = 11 } i-- > 0' < your_file

When "CUST_REF" is seen on a line, a counter is set for 11 lines. The next pattern selects all lines for which the counter is bigger than 1 and decrements the counter (after the comparison is made --- this is important), but because there is no action associated with it, the default action of "print the current line" is taken.

The perl is similar:

perl -lne '$i = 11 if /CUST_REF/; print if $i-- > 0' < your_file

The perl has the advantage of not having a line length limit (which may not affect your case).