Remove Carriage Return from the end of the file

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Remove Carriage Return from the end of the file

Post by kashif007 »

Hello All

I am producing a fixed width file with a carriage return in the last column of each record in the file. The business wants carriage return on all other records except the last record. Can anyway suggest me how can I remove the carriage return at the EOF. If possible, I don't want to remove the carriage return but replace the last carriage return with a space. That way I maintain the fixed length of the record intact.

Thanks
Regards
Kashif Khan
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

check the record delimiter string option of seq file stage it that helps.
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

I have already tried various Sequential file options but it did not help. I am looking for a UNIX command to fix this issue.

Following is the scenario. I have a file called "file1" which has the following content.

abc
xyz
123
etc
etc
etc
<-------------------- Blank line to remove

How do I get ride of this blank line at the end. I have already tried the following SED command

sed "$d" file1 > file2

but the carriage return does not go away.
Regards
Kashif Khan
paultechm
Participant
Posts: 27
Joined: Wed Jul 25, 2007 2:09 am

Re: Remove Carriage Return from the end of the file

Post by paultechm »

Hi,
Read the file as a single varchar column(without data length) , remove the blank line based on the length.Use column export to split the records into multiple columns

-Paul
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

kashif007 wrote:I have already tried various Sequential file options but it did not help. I am looking for a UNIX command to fix this issue.
If it is unix that you want to work with, the below should help you.

sed '$d' xyz.dat>tmp.dat
tail -1 xyz.dat|tr -d \n>>tmp.dat
mv tmp.dat xyz.dat
Post Reply