Help with Shell Script

Hi friends,

I need help to create shell script on following server
Linux nnos4 2.6.9-100.ELsmp #1 SMP
x86_64 x86_64 x86_64 GNU/Linux

I have 2 input files - file1.txt and file2.txt

#cat file1.txt
name = peter
address = nsw
 
item = bike
count = 1
 
item = car
count = 2

--------------------------------------------

#cat file2.txt
name = robin
address = central
phone = 4237658
 
item = car
count = 3
type = sedan

And I need output of the file in the following format which I need to show in excel format column seperated.

name address phone item count type
peter nsw bike 1 
peter nsw car 2 
robin central 4237658 car 3 sedan

Can someone help me with this .

Thanks a lot

---------- Post updated at 11:44 AM ---------- Previous update was at 11:41 AM ----------

Hi friends,

I need help to create shell script on following server
Linux nnos4 2.6.9-100.ELsmp #1 SMP
x86_64 x86_64 x86_64 GNU/Linux

I have 2 input files - file1.txt and file2.txt

#cat file1.txt
name = peter
address = nsw
 
item = bike
count = 1
 
item = car
count = 2

--------------------------------------------

#cat file2.txt
name = robin
address = central
phone = 4237658
 
item = car
count = 3
type = sedan

And I need output of the file in the following format which I need to show in excel format column seperated.

name address phone item count type
peter nsw bike 1 
peter nsw car 2 
robin central 4237658 car 3 sedan

Can someone help me with this .

Thanks a lot

Sorry but the design does not make sense. The first two data lines do not match the column headings. There is no sensible way to program this.

By "excel format column seperated" did you actually mean "Excel format comma separated"?

Also, please mention what Shell you are using and show any attempts at a solution.

Hi Friend,

I am able to make script for this one.

I got ouput in following format whose output is fine as required.
peter|nsw||bike|1|
peter|nsw||car|2|
robin|central|4237658|car|sedan|3|

My actual files are as below, little formated at headers and values

cat file1.txt
-------------
prn = youlimit
pri = 3520
rg = 351
pre = enable
prec = 35343
pra = statistics
filter = yout
uri = *yout*
pid = 6
dpl = 8080
fs = enable
prec = 10
------------------------------------------------------------------------
cat file2.txt
-------------
prn = deafemer
pri = 4932
rg = 491
pre = enable
prec = 492239
pra = pass

fil = deafemer-1
pid = 6
fs = enable
daddr = 202.121.124.1
prec = 10
fil = deafemer-2
pid = 6
fs = enable
daddr = 202.121.124.2
prec = 20

And requires its ouput in following format
prn|pri|rg|pre|prec|pra|filter|uri|pid|dpl|fs|daddr|prec

If you could help me on this.

thanks

---------- Post updated at 06:23 PM ---------- Previous update was at 06:21 PM ----------

Below is the code I used to make the script for the previous one
#!/bin/sh
for i in 1 2
do
while read line
do
a=`echo $line | awk '{printf $1}'`
b=`echo $line | awk '{printf $3}'`
if [ "$a" == "name" ]
then
c1=$b;
fi;
if [ "$a" == "address" ]
then
c2=$b;
fi;
if [ "$a" == "phone" ]
then
c3=$b;
fi;
done <file$i.txt
#echo $c1 $c2 $c3
while read line
do
a=`echo $line | awk '{printf $1}'`
b=`echo $line | awk '{printf $3}'`
for (( l=1 ; l<=1 ; l++ ))
do
if [ "$a" == "item" ]
then
e[$l]=$b;
printf "\n"$c1"|"$c2"|"$c3"|"${e[$l]}"|";
fi;

if [ "$a" == "type" ]
then
f[$l]=$b;
printf ${f[$l]}"|";
fi;
if [ "$a" == "count" ]
then
d[$l]=$b;
printf ${d[$l]}"|";
fi;
#if [ "$a" == "type" ]
#then
#f[$l]=$b;
#printf ${f[$l]}"|";
#fi;
done
done <file$i.txt
printf "\n";
done