CSV processing to XML

Hi,
i am really fresh with shell scripting and programming,
i have an issue i am not able to solve to populate data on my server for Cisco IP phones.
I have CSV file within the following format:
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;CUSTOME NAME :;;CompanyX;;;;;;;;;PACKAGES;;;;;English
;;;;;;;;;;;;;standard;;;;;English
;;;;;;;;; ;;;;secretary;;;;;German
;;;;;;;;;;;;;;;;;;
;No;NAME;FAMILYNAME;TELEPHONE NUMBER;EXTENSION;E-MAIL;PREFERRED LANGUAGE;CUSTOMER PACKAGE;COUNTRY CODE;SIP PASSWORD;TIMEZONE
;1;test;customer;01235870;200;test@customer.org;English;secretary;English;1234;1234;ECT;;;;;;
;2;test;tester;01235871;201;test@customer.org;English;secretary;English;1234;1234;ECT;;;;;;
;3;user;customer;01235872;202;test@customer.org;English;secretary;English;1234;1234;ECT;;;;;;
;4;john;wayne;01235873;203;test@customer.org;English;secretary;English;1234;1234;ECT;;;;;;
;5;;;;;;;;;;;;;;;;;
;6;;;;;;;;;;;;;;;;;

and i would like to take a data from this CVS and file out XML format that Cisco IP phones can understand.
I care for CUSTOMER NAME, NAME, FAMILYNAME and TELEPHONE NUMBER other fields can be ignored.

<CiscoIPPhoneDirectory>
<Title>Directory title goes here</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>The name of the directory entry</Name>
<Telephone>The telephone number for the entry</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>

Example:
<CiscoIPPhoneDirectory>
<Title>CompanyX</Title>
<Prompt>People reachable via VoIP</Prompt>
<DirectoryEntry>
<Name>Test Customerr</Name>
<Telephone>012345870</Telephone>
</DirectoryEntry>
<CiscoIPPhoneDirectory>

Thank you all in advance

if you have Python

#!/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

# ./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>

what have you tried till now??
I can give you some hints please give a try..
in awk first check for those fields with delimitar as ";"
if they are present print them in your req format.
NOTE:if that CSV is very huge it will take bit time

as i am new with shell scripting i have tried to write something using sed/awk but i am stocked

can you post the code which you tried may be we help you to correct that...

thanks to ghostdog74
seems it works fine.
shell scripting, python and this kind of staff seems a very powerful

once again thx a lot

i have tried this way, cause i find out sed/awk are good for text processing

# sed -e 's/;/ /g' file | awk 'NR==10 { print $3 } '
to get Company name
and to get entries
# sed -e 's/;/ /g' file | awk 'NR==21 { print $2, $3, $4 } '
so i get something like this:
test customer 01235870

but did not know what to do with this
sorry but i did not much to correct
i am not sure if shell can handle this

 -----Post Update-----

Hi,

can someone take a look into and help me out a bit. Python script posted by ghostdog74
works fine except puting compayn name into and when i start script i get this error

./test.py 
Traceback (most recent call last):
  File "./test.py", line 26, in ?
    print s.substitute(company=COMP, name=NAME,telephone=TEL)
NameError: name 'COMP' is not defined

but to quickly things working i did this:

and i got output like this:
CODE:
test.py 

#!/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("filee"):
    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="CUSTOMER NAME", name=NAME,telephone=TEL)

and OUTPUT:
<CiscoIPPhoneDirectory>
<Title>CUSTOMER NAME</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>test customer</Name>
<Telephone>01235870</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>


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

i am not able to get Customer Name variable into 

any help i would be greatful

 -----Post Update-----

Hi,

can someone take a look into and help me out a bit. Python script posted by ghostdog74
works fine except puting compayn name into and when i start script i get this error

./test.py 
Traceback (most recent call last):
  File "./test.py", line 26, in ?
    print s.substitute(company=COMP, name=NAME,telephone=TEL)
NameError: name 'COMP' is not defined

but to quickly things working i did this:

and i got output like this:
CODE:
test.py 

#!/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("filee"):
    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="CUSTOMER NAME", name=NAME,telephone=TEL)

and OUTPUT:
<CiscoIPPhoneDirectory>
<Title>CUSTOMER NAME</Title>
<Prompt>Prompt text goes here</Prompt>
<DirectoryEntry>
<Name>test customer</Name>
<Telephone>01235870</Telephone>
</DirectoryEntry>
</CiscoIPPhoneDirectory>


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

i am not able to get Customer Name variable into

any help i would be grateful

look at this line :

if "CUSTOMER NAME" in line:

does your file have CUSTOMER NAME in it? In your sample file, i think you have a CUSTOME NAME. The "R" is missing. If you really have the word CUSTOME, then change the code appropriately. don't use my code blindly.

hi all,

thx a lot for your help.
i managed to get demo working.
Could you please help me with some good links cause i would like to learn more about shell scripting. i have found a lot of links but would like to get some your recomendation.

Once again thx

Advanced bash scripting
Python programming