Naveen Naveen - 6 months ago 10
Bash Question

Fetch the lines between a file when a same pattern comes at the starting of line

Please find my problem below.

I need to fetch the records from a file and split it into various files when the first 2 characters of the line is 10 till the next 10 appears.Its like line starting with 10 is header records and data, again for another data header begins.

Input file:

10000002221300000223............................etc some informations
Data...
data....
data..
data....
data....
10000002332200006556...........................etc some informations
data2
data2
data2
data2
data2


Output file1:

10000002221300000223............................etc some informations
Data...
data....
data..
data....
data...


Output file2:

10000002332200006556...........................etc some informations
data2
data2
data2
data2
data2

Answer

The following should help you

 awk 'BEGIN {FILE_NAME="output_prefix"; INX=0; } /^10/{INX++; print $0 > (FILE_NAME INX); } {print $0 >> (FILE_NAME INX);}' ; 

It will create files

 output_prefix1
 output_prefix2
 output_prefix3
 etc