Spliting a file into smaller files based on a particular hierarchy/pattern.

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

Spliting a file into smaller files based on a particular hierarchy/pattern.

Venkat
This post was updated on .
Unix Script:

AD,00,--,---,---,---,---,---,---,--,--,---
   AM,000,---,---,---,---,---,---
   AR, ,---,--,---,---
   AA,---,---,---,---
   AT,---
   AU,---,---,---
   AS,---,---
   AP,---,---,---
   AI,---
AD,00,---,---,---, ,---,---,---,---,---,---
   AM,000,---,---,---
   AR, ,---,---,---
   AS,---,---
AD,01,---,---,---,---,---,---,---,---,---
   AA,001,---,---
   AU,---,---,---
AD,00,---,---,---,---,---,---,---,---,---,---
   AP,---,---,---,---,---,---,---
AD,01,---,---,---,---,---
   AS,---,---,---,---
   AI,---,---


Basics of file:
Record starting with 'AD' is the parent record and all the sub records starting with other sequences are its properties (of parent 'AD' record).
"," is the delimiter for the file.
Here 1 hierarchy means: Record starting with 'AD' and all its sub-records i.e. till we encounter another 'AD' record
There may be as lowest as 1 property or as highest as 8 properties for each hierarchy ('AD' record).
There may be millions of such hierarchies...

Could you please help me to split the master file into several sub files using UNIX script such that each sub file contain 1000 hierarchies each (1000 'AD' records along with their properties records)
I have an idea on splitting the file based on first field, but not sure how to split it based on a hierarchy or pattern.
Reply | Threaded
Open this post in threaded view
|

Re: Spliting a file into smaller files based on a particular hierarchy/pattern.

Arun N
Hi,

I am looking for  a way to

Split the file into multiple files at every 1000th occurrence of the pattern START
Reply | Threaded
Open this post in threaded view
|

Re: Spliting a file into smaller files based on a particular hierarchy/pattern.

Guru
Administrator
Please refer to this article for examples on how to split:

http://www.theunixschool.com/2012/06/awk-10-examples-to-split-file-into.html