Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Break one file into multiple

Status
Not open for further replies.

preethib

Programmer
Jul 20, 2000
39
IN
Hi,

I have a file in the following format. I want to break the file into seperate files based on [Local], [Global]...... These separators are predefined.
I tried getting line number for the variables using awk. But did not work.

regards,


[Local]
JDoe12345,John Doe,,Product Division - Materials,,simon,,ukuser
HDoe32456,Harry Doe,,sales Division - Materials,motif,,,usauser
.
.
#All the above lines should be output to a file

[Global]
LDoe12345,Larry Doe,august,Product Division - spares,,,,reguser
KDoe32456,Karen Doe,,Product Division - spares,,,all,usauser
..
#All the above lines from [Global] should be output to a different file

[Network]
similar to above
..

#All the above lines from [Network] should be output to a different file




 
If you look unde the "unixadmin" post on this page you
will find a pattern matching script that will
allow you to do what you want.
 

I haven't found the marsd post ...

A possible solution :

$1 ~ /^\[.*\]/ {
PrvSep = Sep ;
sub("\[.*\].*","&",$1) ;
Sep=substr($0,2,length($1)-2) ;
FicSep = "./" Sep ".txt" ;
if (PrvSep != "") close(FicSep) ;
next ;
}
FicSep != "" {
print $0 > FicSep ;
}
Jean Pierre.
 
Aigles,
Krunek and you yourself posted a pat matching script
that divided a file into body:header pairs under the
query posted by "unixadmin". on this page.
if you redirect the body under each query header to a
separate file, this should work for this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top