1753713 Members
4610 Online
108799 Solutions
New Discussion юеВ

Add return feed.

 
SOLVED
Go to solution
Jack Daniels_1
Occasional Contributor

Add return feed.

Hello!

I get these files from NT world. When i open them with vi, i get the message "Incomplete Last line". Also each line has ^M characters except the last line. I am tryin to use sed to strip the ^M characters (cat $file | sed 's/^V^M//g' > $file.new) but this deletes the last line too.
So i am trying to figure out some way to add a return feed to just the last line before running the sed part.

I assume this will retain the last line after running the sed part.

Any help is greatly appreciated.
TIA.
11 REPLIES 11
Pete Randall
Outstanding Contributor
Solution

Re: Add return feed.

Check out the dos2ux command.

Pete

Pete
Bill McNAMARA_1
Honored Contributor

Re: Add return feed.

try
dos2ux filename > filename.ux
similarly
ux2dos filename.ux > filename.winders

Later,
Bill
It works for me (tm)
A. Clay Stephenson
Acclaimed Contributor

Re: Add return feed.

The dos2ux command will do this for you. Man dos2ux.

Plan B. If you are transferring these files via FTP, use the ascii command prior to the put or get and the conversion will be automatic.
If it ain't broke, I can fix that.
MANOJ SRIVASTAVA
Honored Contributor

Re: Add return feed.

Hi Jack


Coupe of ways to do it


dos2ux filename > newfileanem

will get rid of the ^M

also


cat filename | sed -e "1,$s/\^M//g" should do the trick



Manoj Srivastava


H.Merijn Brand (procura
Honored Contributor

Re: Add return feed.

Other ways than dos2ux just posted today in http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xd6f956bd90a9d611abdb0090277a778c,00.html
Enjoy, Have FUN! H.Merijn
Jean-Luc Oudart
Honored Contributor

Re: Add return feed.

Nearly same question, but same solution applies :

cat | tr -d "\r" >

Jean-Luc
fiat lux
MANOJ SRIVASTAVA
Honored Contributor

Re: Add return feed.

H.Merijn Brand (procura
Honored Contributor

Re: Add return feed.

MANOY, not that I begrudge you points, but what does your answer add to mine? more than 10 minutes later. I guess you would have read the thread before you post.

N/A
Enjoy, Have FUN! H.Merijn
Jack Daniels_1
Occasional Contributor

Re: Add return feed.

THanks to everyone for the immediate response. (yes, i need to go back and give points.)

To go back to the problem...
Oops, My mistake!(So full marks to everyone) I forgot to mention that i have already tried the dos2unix option. It removes the ^M fine but the subsequent job which uses the file fails.

So i manually added a return to the end of the last line and it works fine.

So it appears that i need to find a way to get a return feed at the end of the last line only.

Any help??
TIA.

I have attached a sample file.