Hi
I have two lines of data formatted as displayed below
shop, price, remark, date
a,#N/A,order to -fd, 20091011
and would like it to be
shop:a
price:#N/A
remark:order to -fd
date:20091011
How can I do it?
Many thanks
Hi
I have two lines of data formatted as displayed below
shop, price, remark, date
a,#N/A,order to -fd, 20091011
and would like it to be
shop:a
price:#N/A
remark:order to -fd
date:20091011
How can I do it?
Many thanks
nawk -F, '
FNR==1 { split($0, headerA, FS; next}
{ for (i=1; i<=NF; i++) print headerA OFS $i }
' OFS=: myFile
Where do you "have" the data?
If they are in a file:
{
read line1
read line2
} < "$FILE"
IFS=,
set -f
set -- $line1 $line2
fields=$(( $# / 2 ))
n=1
while [ $n -le $fields ]
do
eval "f1=\${$n} f2=\${$(( $n + $fields ))}"
printf "%s:%s\n" "${f1# }" "${f2# }"
n=$(( $n + 1 ))
done
Otherwise, put the first line in $line1 and the second in $line2 and use everything from IFS=, on.