Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

removing repeating/duplicate control char

23 views
Skip to first unread message

peter sands

unread,
Mar 15, 2013, 3:31:58 PM3/15/13
to
Hello,

I have a text file where I need to get rid of a repeating control character, I have tried sed and tr but not getting the results I expect.
The text file is as an example:

^M
text here
text here
^M^M
text here
text here
^M

I need to remove the repeating character of ^M so I have:

^M
text here
text here
^M
text here
text here
^M

Any idea's please
PS

Aragorn

unread,
Mar 15, 2013, 3:58:17 PM3/15/13
to
On Friday 15 March 2013 20:31, peter sands conveyed the following to
comp.unix.shell...
sed 's/\^M//' FILE.IN > FILE.OUT

--
= Aragorn =

http://www.linuxcounter.net - registrant #223157

Thomas 'PointedEars' Lahn

unread,
Mar 15, 2013, 4:15:15 PM3/15/13
to
What have you tried?

--
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Ben Bacarisse

unread,
Mar 15, 2013, 10:05:56 PM3/15/13
to
peter sands <peter...@techemail.com> writes:

> I have a text file where I need to get rid of a repeating control
> character, I have tried sed and tr but not getting the results I
> expect. The text file is as an example:
>
> ^M
> text here
> text here
> ^M^M
> text here
> text here
> ^M
>
> I need to remove the repeating character of ^M so I have:

If you know how to type a literal Ctrl+M at your shell is should be
obvious. On my system I type Ctrl+V before Ctrl+M. The Ctrl+V character
acts like a quote (it's called 'lnext' for 'literal next' in the tty
settings).

Now you can just type

tr -s ^M

or

sed -e s/^M^M*/^M/g

However, in tr you can write the character using tr's own escape
syntax so maybe the problem is not knowing what the character is?

<snip>
--
Ben.

Reinhard Skarbal

unread,
Mar 16, 2013, 12:01:35 PM3/16/13
to

"peter sands" <peter...@techemail.com> schrieb im Newsbeitrag
news:8fa0961c-0ddb-44ab...@googlegroups.com...
Hi Peter
Just from brain. Try
tr -d '\r' <infile >outfile

Regards
Reinhard


Barry Margolin

unread,
Mar 16, 2013, 12:32:18 PM3/16/13
to
In article <ki250q$v4n$1...@news.albasani.net>,
That will remove ALL ^M's from the file, he just wants to remove the
repeated ones.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Ben Bacarisse

unread,
Mar 16, 2013, 4:55:17 PM3/16/13
to
"Reinhard Skarbal" <reinhard...@aon.at> writes:

> "peter sands" <peter...@techemail.com> schrieb im Newsbeitrag
> news:8fa0961c-0ddb-44ab...@googlegroups.com...
<snip>
>> I need to remove the repeating character of ^M so I have:
<snip>
> Just from brain. Try
> tr -d '\r' <infile >outfile

tr -s '\r' <infile >outfile

The -s is for "squeeze" rather than -d for "delete" which is what the OP
wanted.

--
Ben.

spender

unread,
Feb 20, 2023, 8:36:04 PM2/20/23
to
USE sed command , find and replace: sed -n ':a;N;$!ba;s/\n\r\r\n/\n/g'
filename

Janis Papanagnou

unread,
Feb 21, 2023, 4:03:58 AM2/21/23
to
On 21.02.2023 02:35, spender wrote:
> 在 2013/3/16 3:31, peter sands 写道:
^^^^^^^^^^^
>> Hello,
>>
>> I have a text file where I need to get rid of a repeating control
>> character, I have tried sed and tr but not getting the results I expect.
>> The text file is as an example:
>> [...]
>
> USE sed command , find and replace: sed -n ':a;N;$!ba;s/\n\r\r\n/\n/g'
> filename

After these 10 years that passed since his post I suppose that peter
sands could have even carved the duplicate control characters out of
marble using a chisel instead of sed.

Janis

0 new messages