Sponsored Content
Full Discussion: CSV processing to XML
Top Forums Shell Programming and Scripting CSV processing to XML Post 302319334 by ghostdog74 on Monday 25th of May 2009 04:46:34 AM
Old 05-25-2009
if you have Python
Code:
#!/usr/bin/env python

import string
s=string.Template("""
<CiscoIPPhoneDirectory>
<Title>$company</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>$name</Name>
<Telephone>$telephone</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>
""")

f=0
for line in open("file"):
    line=line.strip()    
    if "CUSTOMER NAME" in line:
        COMP=line.split(";")[4]
    elif "FAMILYNAME" in line: f=1;continue
    if f :
        sline=line.split(";")
        if sline[2]:
            NAME =' '.join(sline[2:4] )
            TEL=sline[4]
            print s.substitute(company=COMP, name=NAME,telephone=TEL)

output
Code:
# ./test.py

<CiscoIPPhoneDirectory>
<Title>CompanyX</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>test customer</Name>
<Telephone>01235870</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>


<CiscoIPPhoneDirectory>
<Title>CompanyX</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>test tester</Name>
<Telephone>01235871</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>


<CiscoIPPhoneDirectory>
<Title>CompanyX</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>user customer</Name>
<Telephone>01235872</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>


<CiscoIPPhoneDirectory>
<Title>CompanyX</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>john wayne</Name>
<Telephone>01235873</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>

 

9 More Discussions You Might Find Interesting

1. Programming

Processing a CSV file

Hi I'm reading a comma separated file record by record. After reading a record, I'm tokenizing it using strtok() function and moving the tokens into a structure. But suppose if a record is of the following format,i.e two commas appear one after another, then the strtok function skips the... (1 Reply)
Discussion started by: janemary.a
1 Replies

2. Shell Programming and Scripting

Shell Script syntax for XML processing

Hi All, I am new to Shell scripting. I have a log file containing XML Messages.Each XML Message is accompanied with a timestamp.I need to count the the number of messages that get logged in a particular timeinterval.Is there any command/Syntax to achieve this. Any code/example is... (5 Replies)
Discussion started by: vignesh53
5 Replies

3. Shell Programming and Scripting

need help on xml processing

I am trying to divide a xml file(my.xml) like this: <?xml version="1.0" encoding="UTF-8"?> <Proto PName="hmmmmmmm"> <Menu id="A" ver="1"> <P> <P name="AA" Type="X"/> <P name="BB" Type="Y"/> <P name="CC" Type="Z"/> </P> ... (4 Replies)
Discussion started by: demoprog
4 Replies

4. Shell Programming and Scripting

Simple Script needed for Processing CSV file perl

I am new to perl, and need a script to pull a CSV file, strip out 2 leading columns, and 2 ending columns, and resave the file in a new location. The file is basic and has less than 10,000 records. Secondly, can I schedule perl scripts to run daily? Can someone provide the basic script to... (1 Reply)
Discussion started by: cobbjob
1 Replies

5. Programming

help me with perl script xml processing

Hi everyone, I have Xml files in a folder, I need to extract some attribute values form xml files and store in a hash. My xml file look like this. <?xml version="1.0" encoding="UTF-8"?> <Servicelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"... (0 Replies)
Discussion started by: pavani reddy
0 Replies

6. Shell Programming and Scripting

Help with XML file processing

I need to get all session_ID 's for product="D-0002" from a XML file: Sample input: <session session_ID="6411206" create_date="2012-04-10-10.22.13.000000"> <marketing_info> <program_id>D4AWFU</program_id> <subchannel_id>abc</subchannel_id> </marketing_info> ... (1 Reply)
Discussion started by: karumudi7
1 Replies

7. Shell Programming and Scripting

processing xml with awk

With the following input sample extracted from a xml file <rel ver="123"> <mod name="on"> <node env="ac" env="1"> <ins ip="10.192.0.1"/> <ins ip="10.192.0.2"/> ... (1 Reply)
Discussion started by: cabrao
1 Replies

8. Shell Programming and Scripting

Shell script for .Txt to .csv conversion with data processing

Hi experts, I want to convert a txt file having rows and columns (CNAI_DUMP_raw.txt) by comparing it with another text file (paramaters.txt) and generate a output in CSV which contains only 3rd column from CNAI_DUMP_raw.txt, and the columns mentioned in parameters.txt. FYI: There are two... (16 Replies)
Discussion started by: Gautam Banerjee
16 Replies

9. UNIX for Beginners Questions & Answers

General Purpose XML Processing

I've been kicking this around for a while now, I might as well post it here. v0.0.9, now properly supporting self-closing tags. v0.0.8, an important quoting fix and a minor change which should handle special <? <!-- etc. tags without seizing up as often. Otherwise the code hasn't changed much.... (6 Replies)
Discussion started by: Corona688
6 Replies
cadubi(1)							   User commands							 cadubi(1)

 others.

NAME
cadubi - Creative ASCII Drawing Utility By Ian DESCRIPTION
cadubi is an application written in Perl that allows you to draw text-based images that are viewable on typical UNIX-based consoles. Usu- ally the applications that emulate these consoles support various text modes, such as background and foreground colors, bold, and inverse. This text art, commonly called "ASCII art", is used in various places such as online BBSes, email and login prompts. OPTIONS
-h --help display some documentation -m--mute turn off beeping -s [W] [H] --size [W] [H] sets the size of the console for use with cadubi, where W is number of columns and H is number of rows. -v --version show cadubi's version CONFIGURING
Beeping and command line options can be also set in /usr/bin/cadubi. KEYBOARD
i j k l Move the cursor around. Holding down shift and typing these keys will move the ursor five spaces instead of one. space Paint the current pen on the screen. return/enter Move the cursor down one line and all the way to the left of the console. delete or backspace or ` Delete the character before the cursor. p Prompt for a pen character f Prompt for foreground color (see section colors). b Prompt for background color (see section colors). g Toggle bold mode. v Toggle inverse mode. shift-w Toggle blink (highly annoying). t Enter text mode. This allows you to type like as if you were using a normal text editor, and all the characters drawn onscreen will use the same mode as the pen Pressing Esc will exit text mode. control-w Refresh the entire screen by redrawing each character. control-r Open a file. control-o Save the file. control-h Show the quick help screen. control-x Exit cadubi. USING
Cadubi has a 'pen' which describes the current mode. Properties of the pen are the painting character, foreground color, background color, bold, inverse, and blink. Whenever you paint or use the text mode, the characters drawn on the screen will have the properties of the pen. The current mode of the pen is shown at the bottom of the console and is what will be drawn on screen when you paint. Typically, fore- ground text colors are the same as background colors, unless the text is bold. If the text is bold, foreground colors are usually lighter than the background color, making text easier to read when the text has the same foreground and background color. Refer to the Quick Help (control-'h') to see what the colors look like on your console. Text mode is an extremely useful feature. Once in the text mode you can type as if you were using a normal text editor, and all the charac- ters drawn onscreen will use the same mode as the pen. To enter text mode, press the 't' key. To exit, press escape. When cadubi reads a file, it will only read as much that will fit in the workspace (the area of the console minus the bottom row [status bar]). To gain more workspace, see the '-s' operator in section "options". Cadubi optimizes its output files to display properly and take up as little space as possible. All cadubi output can be viewed with the 'cat' utility. COLORS
The color codes are case-insensitive. The following color codes can be chosen as fore- or background colors: 0 or N - Normal (standard text) 1 or W - White 2 or R - Red 3 or G - Green 4 or Y - Yellow 5 or B - Blue 6 or M - Magenta 7 or C - Cyan 8 or K - Black WARNING
Cadubi uses escape sequences for things like color. These may differ from system to system. This means that the file generated by cadubi may trash your console when viewed with for example cat. It is generally safe to use the files on the same type of console as they were generated on. AUTHORS
Cadubi was created and is currently being maintained by Ian Langworth. Please send all questions, comments, hate mail and bug reports to cadubi@logicallemon. com SEE ALSO
The "Keyboard and Console HOWTO" and the "Text Terminal HOWTO" from the Linuxdoc project (www.linuxdoc.org). Both are available in a Debian GNU/Linux system by installing the doc-linux-text package at /usr/share/doc/HOWTO/en-txt/Keyboard-and-Console-HOWTO.gz and /usr/share/doc/HOWTO/en-txt/Text-Terminal-HOWTO.gz respectively. This man page was copy-pasted from other documentation by Abel Daniel (abli@mai lbox.hu) for the Debian GNU/Linux distributions, but can be used by others. Abel Daniel 1.1b1-4 cadubi(1)
All times are GMT -4. The time now is 05:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy