i have tried this way, cause i find out sed/awk are good for text processing
Code:
# 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>
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)
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)
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)
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)
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)
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)
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)
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)