Domanda

Fairly experienced with bash/ksh scripting but not too familiar with awk. I've had a google but can't find an answer yet. Here's the problem.

We get XML files in, which are in the form of one huge string... The customer has requested we provide a breakdown, but with an average of 1.2k transactions in these files, it's not a manual job.

I've tried setting the IFS delimiter to for example, but it's not working. I've also tried setting the delimiter to '<' but that doesn't seem to play nice either.

So, how can I parse XML with bash or ksh? I'd love to seperate each record by its opening tag. Or simply put each one on a new line...

Thanks.

È stato utile?

Soluzione

You could split the file using ksh/bash like this:

    #!/usr/bin/ksh

    IFS="<"
    printf "<%s\n" `cat $1` 

Then above script would be used as following (assuming name is xmlparse.sh)

    ./xmlparse.sh $your_one_line_xml > ${your_one_line_xml}_new

You might need to adjust the result like deleting first line or you could play with IFS value so that you could split the file based on some tag name only.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top