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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing CR/LF from a file

Status
Not open for further replies.

josem

Programmer
Dec 7, 2000
4
US
I'm fairly new to unix. I got a data file with records that were extracted from oracle. Each of these records has a line break at the end, but I need to join all the records into one large string. (remove CR/LF)

Is there any way that I can do this from unix ??

I've tried sed 's/^M$//g ' f1 > f2

but it does not seem to work !!

any help is appreciated. code is much !! appreciated.

Thanks,
Jose
 
Jose,

try

sed 's/^M^L//' f1 > f2

Mike
michael.j.lacey@ntlworld.com
 
Try tr -d, don't remeber thr syntax completly but i think it's something like this : tr -r &quot;<'15>&quot; file1 file2
 
If you edit the DOS text file with the &quot;vi&quot;
editor in UNIX, use the following from the
&quot;vi&quot; command line:

:%s/^V^M//g

From a Unix shell use the command:

% sed 's/^V^M//g' foo > foo.new

NOTE: ^V is control V and ^M is control M or Enter


 
Thank you all for your replies. I've got the file as I wanted it.

One more question. Is it possible to remove just the Line feed from the file leaving the CR character in the file ??
 
dos2unix? or is that the other way around?
 
I am stealing some code here!...

But see if this gives you any advantage on your problem.

Cut here
------------------------
#include <stdio.h>

void main ()
{
int ch;

/* Print all stdin */
while ((ch = getchar()) != EOF)
{
putchar(ch);

/* LF = CR + LF */
if (ch == '\n')
{
putchar('\r');
putchar('\n');
}
}
}
---------------------------
cut here

L8ter!! Life is good!, live it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top