Solved

How to replace end of line characters

Posted on 2004-09-22
6
1,220 Views
Last Modified: 2013-12-26
Hello,
I learned it but I can't remember it!

When I bring over datafiles from my Windows XP box to upload into the Oracle DB I save the Excel file as a .csv file.  I then FTP it to the UNIX box.

When I open it up in VI on the UNIX box (HPUX 10.2) I have ^M as the end of line character for each line.

How do I do a replace with nothing on the ^M using Replace, SED or whatever??.  Should I be changing a setting somewhere in my FTP so that I don't get the odd character??

Thanks, Jerry (just learning)
0
Comment
Question by:geraldw
6 Comments
 
LVL 11

Accepted Solution

by:
avizit earned 50 total points
ID: 12123405
do check if your unix has a

dos2unix command  i.e do a "which dos2unix "

if it exists you can simply do a

dos2unix filename

0
 
LVL 11

Expert Comment

by:avizit
ID: 12123417
and also

perl -p -e 's/\n/\r\n/' < unixfile.txt > winfile.txt
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12123582

You could use this tr command to filter ^M chars from its std input:

tr -d "\015"

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12123624
The other option is to use ascii mode (rather than binary mode) in FTP,
which performs the translations for you.  check out the 'ascii' and 'cr'
ftp commands in the man page.
0
 
LVL 18

Expert Comment

by:liddler
ID: 12123948
just for completion
sed 's/^M//g' winfile.csv > unixfile.csv
0
 

Author Comment

by:geraldw
ID: 12124232
Thanks folks,
it looks like all are good answers and I'll give the points to avizit since he was first.  Thanks for the other suggestions.  I know I'll use them at some point.
J
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now