Need to split a file bsed on content

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Need to split a file bsed on content

Anju
Hi,
I have a big file like this
header line1
details1
details2
details3
details4
header line2
details1
details2
details3
header line3
details1
details2

I need to split the file into multiple files of fixed lines around(1000 lines), provided the detail records under each header should't get splitted into different files. So the output should be
file-1
------
header line1
details1
details2
details3
details4
header line2
details1
details2
details3
file-2
-------
header line3
details1
details2

Please help.
Reply | Threaded
Open this post in threaded view
|

Re: Need to split a file bsed on content

Guru
Administrator
 Can you please specify the count is being used for the above sample output?
Reply | Threaded
Open this post in threaded view
|

Re: Need to split a file bsed on content

Anju
We have to limit the file count by 1000. All the "Detail records" of a "Header record" should be under that header. So if the splitting is happening between two details,(one detail record in file1 and other in file2) we have to append that Details to file1.
Reply | Threaded
Open this post in threaded view
|

Re: Need to split a file bsed on content

Deepak
In reply to this post by Anju
You can split in this way:

sed -i '/header/i file ------' filename