![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to view the contents of .gz file without extracting the file? | amitkhiare | Shell Programming and Scripting | 5 | 10 Hours Ago 11:29 AM |
| search for the contents in many file and print that file using shell script | cdfd123 | Shell Programming and Scripting | 3 | 10-07-2007 07:17 PM |
| append file name contents to a target file | gopskrish | UNIX for Dummies Questions & Answers | 2 | 10-27-2006 03:18 AM |
| Reading specific contents from a file and appending it to another file | dnicky | Shell Programming and Scripting | 5 | 10-04-2005 02:45 AM |
| ls contents of a file | douknownam | Shell Programming and Scripting | 7 | 06-14-2004 06:29 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
Hi,
I cannot install it because I am not the system admin. And I am using a server from the company. I guess I can't use Ruby. |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Hi,
I couldn't get the 2nd field into the output file. Can you please advise on how to add the 2nd field and so on? Quote:
|
|
#10
|
||||
|
||||
|
Show us what you have done so far.
|
|
#11
|
||||
|
||||
|
Quote:
Code:
IFS="," while read conti country city id do CONT=$conti COUNTRY=$country CITY=$city ID=$id header $ID done < input.file |
|
#12
|
|||
|
|||
|
There are some changes in the requirements of the output file. One more fields needed.
There are also 2 more fields in the input file and the 2nd line is not needed. This is what I have done: Code:
#!/bin/ksh
HEADER='<?xml version="1.0"?>
<!DOCTYPE ALR [
<!ENTITY gt "&gt;">
<!ENTITY lt "&lt;">
<!ENTITY quot "&quot;">
]>
<datafile>
<info ID="'
BODY1=' <info1>'
BODY2=' <info2> </info2>
<info3>'
BODY3=' <info4>'
BODY4=' <info5>0</info5>
<info6> </info6>
<info7> </info7>
<info8>'
BODY5=' <info9>some fixed data</info9>
<info10>some fixed data</info10>
<info11>some fixed data</info11>
</info>
<action>
<attributes>
<attributkey id="011" >N</attributkey>
<attributkey id="106" >N</attributkey>
<attributkey id="114" >N</attributkey>
<attributkey id="119" >N</attributkey>
</attributes>
<comment> </comment>
</action>
</datafile>'
INPUTFILE=/home/dir/input.csv
OUTPUTFILE=/home/dir/output.xml
function header {
echo "$HEADER" > $OUTPUTFILE
echo "$id" >> $OUTPUTFILE
echo "\">" >> $OUTPUTFILE
}
function body1 {
echo "$BODY1" >>$OUTPUTFILE
echo "$continent" >>$OUTPUTFILE
echo "</info1>" >>$OUTPUTFILE
}
function body2 {
echo "$BODY2" >>$OUTPUTFILE
echo "$country" >>$OUTPUTFILE
echo "</info3>" >>$OUTPUTFILE
}
function body3 {
echo "$BODY3" >>$OUTPUTFILE
echo "$city" >>$OUTPUTFILE
echo "</info4>" >>$OUTPUTFILE
}
function body4 {
echo "$BODY4" >>$OUTPUTFILE
echo "$date" >>$OUTPUTFILE
echo "</info8>" >>$OUTPUTFILE
}
function body5 {
echo "$BODY5" >>$OUTPUTFILE
}
IFS=;
while read continent country city id address date
do
ID=$id
CONTINENT=$continent
COUNTRY=$country
CITY=$city
DATE=$date
header $ID
body1 $CONTINENT
body2 $COUNTRY
body3 $CITY
body4 $DATE
body5
done < $INPUTFILE
Code:
continent;country;city,id;address;date ---------;-----------;----------------;----------;---------;-------- asia;japan;tokyo;123;apple road;12012000 europe;germany;munich;456;orange street;13072001 africa;eygpt;cairo;789;banana lane;06121999 |
|
#13
|
||||
|
||||
|
In
Code:
while read continent country city id address date
do
ID=$id
CONTINENT=$continent
COUNTRY=$country
CITY=$city
DATE=$date
header $ID
done < $INPUTFILE
You are invoking the function header with $ID as a parameter. So inside the header function, this parameter $ID is accessible using the construct $@ or $1 ( anyway you like...) So in your case, the header function has no idea what $id is. Hence it should be Code:
function header {
echo "$HEADER" > $OUTPUTFILE
echo "$@" >> $OUTPUTFILE
echo "\">" >> $OUTPUTFILE
}
|
|
#14
|
|||
|
|||
|
Hi,
I have tried with Code:
function header {
echo "$HEADER" > $OUTPUTFILE
echo "$@" >> $OUTPUTFILE
echo "\">" >> $OUTPUTFILE
}
|
|||
| Google The UNIX and Linux Forums |