Sponsored Content
Top Forums Shell Programming and Scripting Generating XML from a flatfile Post 302665957 by Corona688 on Tuesday 3rd of July 2012 12:27:06 PM
Old 07-03-2012
Code:
$ cat flat2xml.awk

BEGIN { FS="," }
NR==1 { next }

{       D[$2,++T[$2]]=$1        }

END {
        print "<whatever>";
        for(X in T)
        {
                print "\t<" X ">";
                        for(N=1; N<=T[X]; N++)  print "\t\t" D[X,N];
                print "\t</" X ">";
        }
        print "</whatever>";
}

$ awk -f flat2xml.awk data

<whatever>
        <Procs>
                Proc1
                Proc2
        </Procs>
        <Views>
                View1
                View2
        </Views>
        <Tables>
                Table1
                Table2
                Table3
        </Tables>
</whatever>

$

It doesn't need to handle more than 2 columns, does it?
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding a column in a flatfile

I have a file which is fixed width columns. This is an offset buffer - rather than space or tab delimited. There are upto about 8 columns and I need to get all of the column 5's values into another file. The problem is that because the delimiter is a space - and some fields are blank - the 5th... (3 Replies)
Discussion started by: peter.herlihy
3 Replies

2. UNIX for Dummies Questions & Answers

encrypting Unix flatfile

Hi, I am new to unix. I have a flat file that needs to be pgp encyrpted in ASCII format and ftped in Ascii format to remote location. Can any one tell me the steps involved in the pgp encryption of the unix file. I will really appreciate if any one can help me with the pgp encryption shell... (1 Reply)
Discussion started by: rkumar28
1 Replies

3. Shell Programming and Scripting

Traverse a flatfile and check for errors

Hi, I need to check a flatfile for various parameters like length of the record, format of record, any tab character present in the record etc., for checking presence of tab character, i'm trying to use the following code and i'm not sure if the same is right. Pls Help. nawk '{print... (1 Reply)
Discussion started by: aravindc
1 Replies

4. Shell Programming and Scripting

Deleting column from a flatfile with delimiter

I have a set of flatfiles which have columns delimited by #. How can a particular column be deleted in all the flatfiles. All flatfiles have same number of columns. (5 Replies)
Discussion started by: rsprabha
5 Replies

5. UNIX for Advanced & Expert Users

Generating XML from XSD

Hi all, Am looking for a way to generate XML based on XSDs so that the final XML need not be validated against the XSDs again. Here is the part of the XSD <xsd:element name="first_element"> <xsd:complexType> <xsd:sequence> <xsd:element name="val"/> </xsd:sequence> ... (0 Replies)
Discussion started by: matrixmadhan
0 Replies

6. Shell Programming and Scripting

Generating an xml having information related to files in the directory

Hi all, Have to generate an xml having information related to files in the directory Suppose i have file file1.xml (datafile) file2.xml (datafile) file3.xml (metafile) Now i need to generate an xml in the format >> <?xml version="1.0" encoding="UTF-8"?> <AuditFile Version="2.0">... (8 Replies)
Discussion started by: abhinav192
8 Replies

7. UNIX for Advanced & Expert Users

Delimeters Count in a FlatFile

Hi, I have the below script to check the count of delimeters for a file (here is File : test.csv Delimeter is ",") awk '{gsub(/"*"/,x);print gsub(/,/,x)}' test.csv And it return the output for each line as: 2 2 cat test.csv: abc,xyz "abc,zxyz",1 I need help one the below things: - IS... (8 Replies)
Discussion started by: venkatajay_18
8 Replies

8. Shell Programming and Scripting

sending output to flatfile

Hi, I am writing one unix script to get row count of few tables into one sequential file my script is like this $ORACLE_HOME/bin/sqlplus -s <<EOF >output.txt userid/password@databasename set verify off set heading off set feedback off select count(*) count from tablel where ; select... (4 Replies)
Discussion started by: spmsarada
4 Replies

9. Shell Programming and Scripting

Parsing a mixed format (flatfile+xml) logfile

I am trying to parse a file that looks like the below: There are thousands of lines like the above and the file is expected to run into hundreds of thousands. The issue i have is the mixed format of the file. If it was just an xmlfile, i would use an xmllint to parse the file. Now, i am... (11 Replies)
Discussion started by: goddevil
11 Replies

10. Shell Programming and Scripting

Generating xml file from UNIX

i have a unix script which generates the csv file. the data in csv file is dynamic. how can i convert/move the data from csv file to xml. please suggest (1 Reply)
Discussion started by: archana25
1 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 06:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy