1827872 Members
1347 Online
109969 Solutions
New Discussion

ASCII File output

 
Sanjay Tailor
Frequent Advisor

ASCII File output

Hello,

How can I take an ASCII file in fixed width format ( fields are separated by spaces or tabs) and convery it to quoted, comma delimited format using HP-UX? Is that possible? Any other solutions?

Thanks in advance for your help,
Sanjay
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: ASCII File output

Hi:

Check the man pages for the various options available with 'tr'. You might find 'sed', 'awk' and/or 'cut' useful for parsing the fields/

...JRF...
Neale Machin
Advisor

Re: ASCII File output

I've previosly used sed for similar
to replace a space with a comma

sed s//,/g

where is a space
is the actual file name
is a temporrary new file holding changed details

To then do the TAB replace space with a physical tab and use newfilename into either another newfile.

Hope this helps
Just cos I look after Unix Boxes doesnt mean I wear sandals
Neale Machin
Advisor

Re: ASCII File output

sed s//,/g

Sorry missed a few critical slashes
this should now work
Just cos I look after Unix Boxes doesnt mean I wear sandals
Neale Machin
Advisor

Re: ASCII File output

Obviously the Resource Center runs UX cos it keeps missing my backslashes off
Please see the attached
file
Just cos I look after Unix Boxes doesnt mean I wear sandals
John Palmer
Honored Contributor

Re: ASCII File output

For ASCII data whose fields are separated by tabs or spaces then a simple shell script will suffice although the shell I/O will remove the spaces and tabs. The following example will read data from standard input:-

#!/usr/bin/sh

while read REC
do
for FIELD in ${REC}
do
print -n "\"${FIELD}\","
done
print
done
Steve Sauve
Frequent Advisor

Re: ASCII File output

If it really is space delimited then you could probably use the "tr" command. Something to the effect of :

cat {filename} | tr " " "," > {new file}

Of course if there are spaces in the data then this would only cause problems.

Hope this helps,
Steve