LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2005, 07:35 AM   #1
zelos
LQ Newbie
 
Registered: Nov 2005
Posts: 1

Rep: Reputation: 0
how to delete CRs?


Hi!

I have to delete carriage return from a file but I don't know hot to.

I tried:

cat myfile.txt| sed -e 's/$//g'

myfile.txt is in unix format, not DOS.

Here's an example:

azerty
uiopq
sdfgh

I'd like to get this:

azertyuiopqsdfgh

Would you please help?

Thanks,
Zelos
 
Old 11-09-2005, 08:46 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
If you want to convert a DOS/Windows ASCII file that contain NewLine/Carriage Return at end of every line to an Unix/Linux ASCII file that contains only NewLine at the end of every line just run the "dos2unix" command.

However to concatenate the way you've indicated is not quite the same thing. You could do something like:

awk 'ORS=" " {print $0}' myfile.txt

This will change the default record separator, newline, to a space. The resulting output though would have NO new lines so would not be recognized as a properly terminated line by many commands.
 
Old 11-09-2005, 09:20 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
The easiest I think is this:
tr -d '\n'

Yves.
 
Old 11-10-2005, 04:46 PM   #4
urka58
Member
 
Registered: Nov 2003
Distribution: slackware 15
Posts: 546

Rep: Reputation: 43
You could also try this short script

#!/bin/sh
for i in `cat myfile.txt`
do
echo -n $i >> myfile.new
done

Ciao
 
Old 11-10-2005, 11:44 PM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
did not read correctly TS post so the answer did not apply

Last edited by Wim Sturkenboom; 11-11-2005 at 01:50 AM.
 
Old 11-11-2005, 03:25 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
tr -d '\015'

in vi:

:g/^V^M/s///
 
Old 11-14-2005, 02:46 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Note: the poster says the file is an Unix file, not DOS, hence it is not the CR (aka. \r or ^M) that need to be deleted, it is the LF instead (that is \n).

Yves.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 09:14 PM
How to Delete? Crimson Star Linux - Newbie 1 01-19-2005 12:33 PM
can I delete these??? adambeazley Linux - Newbie 8 05-07-2004 04:36 PM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 02:46 AM
how to delete? RRMitsu Linux - General 1 12-26-2002 02:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration