Frank.bit of confusion.so new message has been posted. [message #98179] |
Wed, 21 April 2004 21:20 |
Venky
Messages: 52 Registered: October 2001
|
Member |
|
|
Hi Frank,
Please provide me the complete code for the cited example. I really didn't know how to modify the code and I tried with the fragment of code given by you. Please note that the fields are separated by pipe(|) and not with comma(,). There are two files as given below.
PNC04212004.dat
----------------
xyz|abc?
abc|xzy𞖷
mno|asdf𞓦
PNC04222004.dat
---------------
asdf|gfg?
lkjlj|lhhi?
jghj|hhhh?
Now with unix shell scripting I need a single file PNC.dat like below. The file name of the corresponding file is the first field.
PNC.dat
-------
PNC04212004|xyz|abc?
PNC04212004|abc|xzy𞖷
PNC04212004|mno|asdf𞓦
PNC04222004|asdf|gfg?
PNC04222004|lkjlj|lhhi?
PNC04222004|jghj|hhhh?
Please help me....
Regards,
Venky.
|
|
|
Re: Frank.bit of confusion.so new message has been posted. [message #98184 is a reply to message #98179] |
Fri, 23 April 2004 08:54 |
jan
Messages: 71 Registered: August 2002
|
Member |
|
|
td=`date +%m%d%y%H%M%S`
mv pnc.dat oldpnc$td.dat
lin="1"
sc=''
for s in pnc*.dat
do
nol=`wc -l $s|tr -s " "|cut -f2 -d" "`
sc=`head -$lin $s|tail -1`
while [[ $lin -le $nol ]]
do
sc=`head -$lin $s|tail -1`
data=`echo $s|cut -f1 -d"."`
echo $sc
echo $data'|'$sc>>pnc.dat
lin=`expr $lin + 1`
done
lin="1"
done
NOTE: please make sure that all the PNC files has one blank line at the end.
This script will rename any existing PNC.DAT so that it doesn't over write/append existing pnc.dat file.
you can modify the script as per your requirement...
hope this helps
Jan
|
|
|