HP3000-L Archives

September 2006, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Johan Harmsen <[log in to unmask]>
Reply To:
Johan Harmsen <[log in to unmask]>
Date:
Wed, 13 Sep 2006 12:33:40 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (84 lines)
 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 *

ATOM RSS1 RSS2