Operating System - HP-UX
1753455 Members
6322 Online
108794 Solutions
New Discussion юеВ

comma delimited file - and carriage return

 
SOLVED
Go to solution
rmueller58
Valued Contributor

comma delimited file - and carriage return

All, I am outputting a file from informix..

adultid,firstname,lastname,homeaddress,city,state,zip,location,

For some reason I transfer the file and it appears the data is contained in one long line..

I need to append a End of Line each record of the file.. Any ideas appreciated..

7 REPLIES 7
T G Manikandan
Honored Contributor

Re: comma delimited file - and carriage return

where do you need the eol after each comma?
James R. Ferguson
Acclaimed Contributor
Solution

Re: comma delimited file - and carriage return

Hi:

Using 'od' (or 'xd' which is an "alias" hardlink) or using 'cat -ev' might help expose any linecontrols.

That said, how would you define "record"? If it's a bare carriage-return delimiter (which is what I suspect), one way to fix it is to do:

# perl -pe 's/\015/\012/g' file

Regards!

...JRF...
rmueller58
Valued Contributor

Re: comma delimited file - and carriage return

at the very end of each line,

For record:
adultid,firstname,lastname,homeaddress,city,state,zip,location,
1234,Joe,smith,1234 main,Omaha,NE,68128,Building10,
1235,John,Doe,4321 Main,Omaha,NE,68128,Building20,


and so on after each "location" (noted in the header..)..
T G Manikandan
Honored Contributor

Re: comma delimited file - and carriage return

Sorry If I am wrong
for a file like

cat /tmp/b
adultid,firstname,lastname,homeaddress,city,state,zip,location,adultid,firstname,lastname,homeaddress,city,state,zip,location,adultid,firstname,lastname,homeaddress,city,state,zip,location,adultid,firstname,lastname,homeaddress,city,state,zip,location

I would do a

awk '{gsub("location,"location,"location\n");print}' /tmp/b

Output as

awk '{gsub("location,"location,"location\n");print}' /tmp/b
adultid,firstname,lastname,homeaddress,city,state,zip,location
adultid,firstname,lastname,homeaddress,city,state,zip,location
adultid,firstname,lastname,homeaddress,city,state,zip,location
adultid,firstname,lastname,homeaddress,city,state,zip,location
rmueller58
Valued Contributor

Re: comma delimited file - and carriage return

James, the perl script did the trick..

For some reason informix is outputting EOL as tab, rather then new line..

I did an inline edit perl -pi -e ......

I am waiting for the client to reply to see if their application accepted the file.

James R. Ferguson
Acclaimed Contributor

Re: comma delimited file - and carriage return

Hi (again):

> For some reason informix is outputting EOL as tab, rather then new line..

If substituting \012 and \015 worked it would have been faster to use 'tr':

# perl -pe 'tr/\015/\012/' file

The same would have applied for a TAB which is \011.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: comma delimited file - and carriage return

Hi (again):

...and I should add that if the only need is a translation of one character to another, we could easily use a pure shell:

# tr "\015" "\012" < file > file.new
# mv file.new file.old

...but then we couldn't have done inplace updates (as you already did) as with:

# perl -pi.old -e 'tr/\015/\012/' file

...leaving a backup copy as "file.old".

Of course, we could use GNU's 'sed' to perform substitutions and inplace edits, but then Perl is so much more fun and scales easily :-)

Regards!

...JRF...