Hello
Use the following posix script
#
# csv.sh: convert a specific csv file to a fixed length fields file
#
Fmt="%-3.3s%-4.4s%-3.3s%-1.1s%-2.2s\n"
Filler="_"
while read a
do
#
# Split the fields
#
f1=`echo $a | cut -f1 -d','`
f2=`echo $a | cut -f2 -d','`
f3=`echo $a | cut -f3 -d','`
f4=`echo $a | cut -f4 -d','`
f5=`echo $a | cut -f5 -d','`
#
# Handle empty strings
#
if [ -z $f1 ]; then; f1=$Filler; fi
if [ -z $f2 ]; then; f2=$Filler; fi
if [ -z $f3 ]; then; f3=$Filler; fi
if [ -z $f4 ]; then; f4=$Filler; fi
if [ -z $f5 ]; then; f5=$Filler; fi
#
# Print the lines, replace the empty string character by a space
#
echo `printf $Fmt $f1 $f2 $f3 $f4 $f5` | sed -e "s/$Filler/ /g"
done
exit 0
Pipe the csv file into the script or use the file as stdin.
cat data.txt | ./csv.sh
Or
./csv.sh < data.txt
This is just one simple approach, there may be much smarter ways to do this
HTH
Johan
-----Original Message-----
From: HP-3000 Systems Discussion [mailto:[log in to unmask]] On Behalf Of prabhu rajkumar
Sent: Tuesday, September 12, 2006 18:13
To: [log in to unmask]
Subject: [HP3000-L] How to read the CSV file in MPE
I have an issue reading the CSV file in MPE. I have to
Hi all,
I have an issue reading the CSV file in MPE. I have to read the CSV file and create the fixed length regords in MPE. Could you please help. For example, If my file is as below
Column A 3bytes
Column B 4bytes
Column C 3bytes
Column D 1byte
Column E 2bytes
abc,123,wzf,,1
123,fgh,34,1,5
My output file should be like below.
abc123 wzf 1
123fgh 34 15
Please do help me out.
Thanks in advance,
Prabhu
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|