Hope someone here can help. I've completed two UNIX classes and am finally trying to make use of what I've learned.
I was given an xml file at work and asked if I could parse out bits of information. I did the original file in excel thinking it was a one time request. However, the request has become more frequent. I decided to write a script to do the parsing for me.
I've been able to use egrep and sed to get the data I need, but because the original data file has everything on seperate lines, my data is coming up on seperate lines as well. What can I do to put all the data from one record on one line?
Here's what I have so far:
read -p "File Name: " file
fileOut="New"$file
exec < $file
egrep "service_number|address|displayName|ProfileNam e" | sed 's/</:/g' |
sed 's/>/:/g' | sed 's/\//:/g' | cut -d: -f2,3 > $fileOut
the original file looks like this:
<cmd>
<Customer>
<service_number>xxxxxxxxxx</service_number>
<address>xxxxxxx xxxxxx xxx</address>
etc
The other catch is that there are more then 20 fields similar to what I listed above and not all records include all fields. If a field is null, it is not listed. So the data is not always in the same place.
Any idea's?