Sponsored Content
Top Forums Shell Programming and Scripting how to parse the file in xml format using awk/nawk Post 302352427 by fpmurphy on Friday 11th of September 2009 10:21:43 AM
Old 09-11-2009
Quote:
there are modules already available in CPAN for xml parsing and creating xml stuff. Try them instead!
Unfortunately, if you look closely at the string, it is not valid XML as it is not well-formed. No XML parser is going to handle this string.

---------- Post updated at 10:21 AM ---------- Previous update was at 09:06 AM ----------

One way of doing it would be to use a mix of sed and awk to parse and process the line
Code:
sed 's/\<d\>/|/g' file | sed 's/\<\/.\>/ /g' | sed 's/\<.\>//g' | sed 's/ \(.\)/,\1/g' | \
sed 's/,|/|/g' |  awk -F'|' '{ printf "%s,%s\n", $1, $2; printf "%s,%s\n", $1, $3 }'

This outputs
Code:
111,222,333,123,234
111,222,333,456,789

Not elegant but it works!
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

2. Shell Programming and Scripting

Need AWk To parse XML logs

Hi , I need an Awk script to parse my log file . 2008-04-26 10:00:13,391 INFO Logger - <?xml version="1.0" encoding="UTF-8" standalone="no"?><2dm tmsg... (0 Replies)
Discussion started by: amit1_x
0 Replies

3. Shell Programming and Scripting

awk/nawk question to format a file

Hi, I am new to awk/nawk, needs help. I want to merge the rows having emplid attribute same into a single row in the following file. In actual this kind of file will have around 50k rows. Here is my input file id|emplid|firstname|dep|lastname 1|001234|test|1001|1 2|002345|test|1032|2... (7 Replies)
Discussion started by: kumar04
7 Replies

4. Shell Programming and Scripting

parsing(xml) using nawk/awk

Hi , I have an xml format as shown below: <Info> <last name="sean" first name="john"/> <period="5" time="11"/> <test value="1",test2 value="2",test3 value="3",test4 value="5"> <old> <value1>1</value1> <value2>2</value2> </old> <new> <value1>4</value1> <value2>3</value2> </new>... (1 Reply)
Discussion started by: natalie23
1 Replies

5. UNIX for Dummies Questions & Answers

Parse XML e report con AWK

Thanks in advance who can answer. I have to make a small shell that after reading an XML file and extract the fields I create a text file with the same fields taken previously in tabular form. I did this parse.awk ---------------------- BEGIN { FS="" } { for(i=2; i<=NF; i+=2) { ... (1 Reply)
Discussion started by: mcarlo65
1 Replies

6. Shell Programming and Scripting

Help nawk parse file

Hello, Hope you are doing fine. I have a file in following format. I only want to process the data inside the section that comes after #DATE,CODE,VALUE #ITEMS WITH CORRECTIONS ....... #DATE,CODE,VALUE 2011-08-02, ID1, 0.30 2011-08-02, ID2, 0.40 2011-08-02, ID3, 0.50 ...... Means... (3 Replies)
Discussion started by: srattani
3 Replies

7. Shell Programming and Scripting

AWK to Parse XML messages

Hello Guys, Please help with AWK problem. I have XML file which contains a list of messages for subjects. Example of the messages: , message=, message=, message=, message=, message=, message=, message=, message= I want to use AWK to parse these xml messages but I am... (7 Replies)
Discussion started by: James_Owen
7 Replies

8. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies

9. UNIX for Beginners Questions & Answers

Date format conversion how to change this from using nawk to awk

Hi, I have a file where I need to change the date format on the nth field from DD-MM-YYYY to YYYY-MM-DD so I can accurately sort the record by dates From regex - Use sed or awk to fix date format - Stack Overflow, I found an example using nawk. Test run as below: $: cat xyz.txt A ... (2 Replies)
Discussion started by: newbie_01
2 Replies
MKDoc::XML::Decode(3pm) 				User Contributed Perl Documentation				   MKDoc::XML::Decode(3pm)

NAME
MKDoc::XML::Decode - Expands XML entities SYNOPSIS
use MKDoc::XML::Decode; my $decode = new MKDoc::XML::Decode qw/xml xhtml numeric/; # $xml is now "Chris' Baloon" my $xml = MKDoc::XML::Decode->process ("Chris&apos; Baloon"); SUMMARY
MKDoc::XML::Decode is a very simple module with pluggable entity decoding mechanism. At the moment there are three modules: xml - Decodes &apos; &quot; &gt; &lt; and &amp; xhtml - Decodes XHTML entities such as &eacute; numeric - Decodes numeric entities such as &#65; That's it. This module and its counterpart MKDoc::XML::Encode are used by MKDoc::XML::Dumper to XML-encode and XML-decode litterals. API
my $decode_object = new MKDoc::XML::Decode (@modules); Constructs a new decode object using the modules specified in @modules. my $decoded = $decode_object->decode ($stuff); Decodes $stuff and returns it into $decoded. Any entity which is not recognized will be returned as is but will trigger a warning. AUTHOR
Copyright 2003 - MKDoc Holdings Ltd. Author: Jean-Michel Hiver This module is free software and is distributed under the same license as Perl itself. Use it at your own risk. SEE ALSO
MKDoc::XML::Encode perl v5.10.1 2004-10-06 MKDoc::XML::Decode(3pm)
All times are GMT -4. The time now is 10:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy