Help with Sed or Awk task

Help with Sed or Awk task

Post by phi » Sat, 26 Jul 2003 10:42:31



Can someone please help me with the following:

I'm trying to rip some data out of an xml file and put it into new
files. I have one big file with 75 xml structures and i want to split
each one into its own file. I've been trying to use sed or awk to do
this, but I suck. So can someone help me? I realize perl is probably
better, but i've never used it.

So basically

<Begining of Structure>

<more xml>
<more xml>
<more xml>

<End of Structure>

<Beginning of Structure>
<more xml>
etc....etc...

I want to pull everything from beginning to end and in between into a
new file and the next structure into another file and so on 75 times.

Thanks in advance.

 
 
 

Help with Sed or Awk task

Post by phi » Sat, 26 Jul 2003 10:44:01


Can someone please help me with the following:

I'm trying to rip some data out of an xml file and put it into new
files. I have one big file with 75 xml structures and i want to split
each one into its own file. I've been trying to use sed or awk to do
this, but I suck. So can someone help me? I realize perl is probably
better, but i've never used it.

So basically

<Begining of Structure>

<more xml>
<more xml>
<more xml>

<End of Structure>

<Beginning of Structure>
<more xml>
etc....etc...

I want to pull everything from beginning to end and in between into a
new file and the next structure into another file and so on 75 times.

Thanks in advance.

 
 
 

Help with Sed or Awk task

Post by Alan Conno » Sat, 26 Jul 2003 11:08:25



Quote:> Can someone please help me with the following:

> I'm trying to rip some data out of an xml file and put it into new
> files. I have one big file with 75 xml structures and i want to split
> each one into its own file. I've been trying to use sed or awk to do
> this, but I suck. So can someone help me? I realize perl is probably
> better, but i've never used it.

> So basically

><Begining of Structure>

><more xml>
><more xml>
><more xml>

><End of Structure>

><Beginning of Structure>
><more xml>
> etc....etc...

> I want to pull everything from beginning to end and in between into a
> new file and the next structure into another file and so on 75 times.

> Thanks in advance.

Do you have csplit?

NAME
       csplit  - split a file into sections determined by context
       lines

SYNOPSIS
       csplit [OPTION]... FILE PATTERN...

DESCRIPTION
       Output pieces of FILE separated  by  PATTERN(s)  to  files
       `xx01',  `xx02', ..., and output byte counts of each piece
       to standard output.

       -b, --suffix-format=FORMAT use sprintf FORMAT  instead  of
 ........

Alan

--
       For Linux/Bash users: Eliminate spam from your life
       with the Mailbox-Sentry-Program. See the post
       MSP (v.1d)  on comp.mail.misc.

 
 
 

Help with Sed or Awk task

Post by Jani » Sun, 27 Jul 2003 07:22:00



> Can someone please help me with the following:

> I'm trying to rip some data out of an xml file and put it into new
> files. I have one big file with 75 xml structures and i want to split
> each one into its own file. I've been trying to use sed or awk to do
> this, but I suck. So can someone help me? I realize perl is probably
> better, but i've never used it.

perl is probably better, but awk is sufficient, if you like to use it.

Quote:> So basically

> <Begining of Structure>

> <more xml>
> <more xml>
> <more xml>

> <End of Structure>

> <Beginning of Structure>
> <more xml>
> etc....etc...

> I want to pull everything from beginning to end and in between into a
> new file and the next structure into another file and so on 75 times.

/BEGIN/,/END/ {
        print > "file-"count".xml"
        next
Quote:}

{ count += 1 }

Substitute 'BEGIN' and 'END' with your tokens, but watch your spelling!
(One of your begin-block-tokens is misspelled.)

The program assumes an empty line (or a non-BEGIN/non-END line to be more
precise) between the data blocks, as seems to be the case in your example.

Quote:> Thanks in advance.

HTH
--
Janis