Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitute with ^M with ^N

Status
Not open for further replies.

preethib

Programmer
Jul 20, 2000
39
IN
Hi All,

How could I write a shell script to substitute ^M with ^N. The file is huge almost 5mb. I want to automate the procedure, hence, i assume vi commands won't be helpfule.

Regards,
 
cat somefile|sed "s/^v^M/^v^N/g" >anotherfile

The ^v is [ctrl-v]
The ^M is [ctrl-m]
The ^N is [ctrl-n]

Try that.
 
Thanks.

I get the following error
test1: 9323 Memory fault(coredump)
I am assuming, it is because of the filesize, but not sure.
 
Hi,
What is ^N? do you mean \n?

Typically when you FTP a Windows document in BINARY form all the <CR><LF> ( ^M^J ) don't get translated to just <LF> (^J) and then when you try to view it in like VI you will see ^M at the end of every line.

If you FTP in ASCII mode as opposed to BINARY mode it will translate all the <CR><LF> to just <LF>.

Just wondering. The Problem with SED is it LINE EDITOR and therefore reads an entire line into its buffer to translate. A line is defined as terminated by a <LF>(^J).

I think it can't handle lines > 1024 or 4096 characters and if your file is missing the LF, it could cause SED to overrun its buffer.

--

 
If it is \n you're after, check whether your flavour of unix has a dos2unix or equivalent available:

dos2unix file1 file2

This will replace all ^M's in your file1 and place a 'clean' copy in file2. Hope this helps.
 
For further info, the AIX equivalent of dos2unix seems to be:

dosread -a file1 file2

Whilst that for SCO is:

dtox filename > output.file

I particularly like the 'dtox'! Betty Ford Unix anyone?
 
Why don't you simply try [tt]tr[/tt]?

I hope it works...
Unix was made by and for smart people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top