^M representation 
Author Message
 ^M representation

Howdy,

I am running the following snippet from a ksh script.

sed "s/\^M$//" $FTPLOG

The ^M is created with the control-v command in vi, but I would like to know
if it can be represented another way. Occasionally, I cut and paste between
telnet sessions, and of course what is pasted is not what ^M was when
originally created. Is there an octal, hex or other representation of ^M that
will also work?

Thanks,
Mike

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://www.*-*-*.com/ ,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts



Sun, 14 Dec 2003 05:14:59 GMT  
 ^M representation

Quote:

>Howdy,

>I am running the following snippet from a ksh script.

>sed "s/\^M$//" $FTPLOG

>The ^M is created with the control-v command in vi, but I would like to know
>if it can be represented another way. Occasionally, I cut and paste between
>telnet sessions, and of course what is pasted is not what ^M was when
>originally created. Is there an octal, hex or other representation of ^M that
>will also work?

I usually do some variation of:

        tr -d '\015'

but others will tell you to look into your system's "dos2unix" and
"unix2dos" commands.



Sun, 14 Dec 2003 05:49:55 GMT  
 ^M representation

Quote:
>>Howdy,

>>I am running the following snippet from a ksh script.

>>sed "s/\^M$//" $FTPLOG

>>The ^M is created with the control-v command in vi, but I would like to
know
>>if it can be represented another way. Occasionally, I cut and paste between
>>telnet sessions, and of course what is pasted is not what ^M was when
>>originally created. Is there an octal, hex or other representation of ^M
that
>>will also work?

>I usually do some variation of:

>    tr -d '\015'

Thanks, but that is not really what I am looking for. I did get a response
that seems to work, but I do not understand the ".$" syntax. Can someone
offer a literal translation please?

s/.$//" file

Thanks,
Mike

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts



Sun, 14 Dec 2003 21:44:58 GMT  
 ^M representation

Quote:

> s/.$//" file

s/x/y/ means to search for an occurance of x and replace it with y.  In the above
".$" is a regular expression meaning the last character of the line to be replaced
with everything between "//" i.e. nothing.  The last character of the line happens
to be the ^M you want removed.


Sun, 14 Dec 2003 22:53:15 GMT  
 ^M representation

Quote:
>> s/.$//" file

>s/x/y/ means to search for an occurance of x and replace it with y.  In the
above
>".$" is a regular expression meaning the last character of the line to be
replaced
>with everything between "//" i.e. nothing.  The last character of the line
happens
>to be the ^M you want removed.

Yes, unfortunately, I tested it on a file where I added ^M 's to the end of
the line, and it removed them. However I do not want to remove the last
character if it is not a ^M, so this suggestion is not going to help me.
Anyone have another suggestion????

Thanks,
Mike

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts



Mon, 15 Dec 2003 02:05:33 GMT  
 ^M representation

Quote:

> >> s/.$//" file

> Yes, unfortunately, I tested it on a file where I added ^M 's to the end of
> the line, and it removed them. However I do not want to remove the last
> character if it is not a ^M, so this suggestion is not going to help me.
> Anyone have another suggestion????

Well, why not the "tr -d '\015' < file" solution or "strings file > newfile" or...
etc....


Mon, 15 Dec 2003 02:23:00 GMT  
 ^M representation

...

Quote:
>Yes, unfortunately, I tested it on a file where I added ^M 's to the end of
>the line, and it removed them. However I do not want to remove the last
>character if it is not a ^M, so this suggestion is not going to help me.
>Anyone have another suggestion????

Yes, I have one.  Why don't you tell us what you are really trying to do,
and why the "tr -d" solution isn't acceptable to you?


Mon, 15 Dec 2003 03:58:08 GMT  
 ^M representation
Quote:
> Yes, I have one.  Why don't you tell us what you are really trying to do,
> and why the "tr -d" solution isn't acceptable to you?

The "tr -d" is a great option, but I already have a solution in sed
"s/\^M$//" file, so I am not really looking for a "solution". This is one of
those things that you run into from time to time and would like to know the
answer to, but at that time you are usually under the gun to produce
results.

What I am looking for is an answer to my original question. Is there
another, perhaps octal, hex or other representation of  ^M that will also
work with sed? Why won't something like sed "s/\015$//" work?

Mike



Mon, 15 Dec 2003 06:26:11 GMT  
 ^M representation

Quote:

>Howdy,

>I am running the following snippet from a ksh script.

>sed "s/\^M$//" $FTPLOG

>The ^M is created with the control-v command in vi, but I would like to know
>if it can be represented another way. Occasionally, I cut and paste between
>telnet sessions, and of course what is pasted is not what ^M was when
>originally created. Is there an octal, hex or other representation of ^M
that
>will also work?

I received the answer from the Prophet of the Way who directed me to section
4.7 of:
http://www.cornerstonemag.com/sed/sedfaq.html

The way to make this happen is:
sed 's/'`echo "\015"`'//g'

Thanks for the help,
Mike

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts



Tue, 16 Dec 2003 07:11:15 GMT  
 ^M representation

Quote:

>> Yes, I have one.  Why don't you tell us what you are really trying to do,
>> and why the "tr -d" solution isn't acceptable to you?
> The "tr -d" is a great option, but I already have a solution in sed
> "s/\^M$//" file, so I am not really looking for a "solution". This is one of
> those things that you run into from time to time and would like to know the
> answer to, but at that time you are usually under the gun to produce
> results.
> What I am looking for is an answer to my original question. Is there
> another, perhaps octal, hex or other representation of  ^M that will also
> work with sed? Why won't something like sed "s/\015$//" work?
> Mike

        Because sed doesn't parse octal constants into
        ASCII characters.  Sed lets you enter the literals
        into your script.  That's sufficient for the authors
        that have implemented and all the people who've used
        it.

        (Every command doesn't need to implement every parsing
        convention.  I don't expect to see "unicode sed" any
        time soon).



Wed, 17 Dec 2003 15:49:36 GMT  
 ^M representation

Quote:

>What I am looking for is an answer to my original question. Is there
>another, perhaps octal, hex or other representation of  ^M that will also
>work with sed? Why won't something like sed "s/\015$//" work?

There are *some* implementations of sed which recognize octal escape
sequences exactly as you describe. Some others recognize hex sequences,
e.g., sed "s/0x34//". I have encountered both in MSDOS versions of sed,
but the responses here seem to point to no Unix versions having this
extension.
--
John Savage            (for email, replace "ks" with "k" and delete "n")


Wed, 07 Jan 2004 07:18:05 GMT  
 ^M representation

Quote:

> >What I am looking for is an answer to my original question. Is there
> >another, perhaps octal, hex or other representation of  ^M that will
also
> >work with sed? Why won't something like sed "s/\015$//" work?

> There are *some* implementations of sed which recognize octal escape
> sequences exactly as you describe. Some others recognize hex
sequences,
> e.g., sed "s/0x34//". I have encountered both in MSDOS versions of
sed,
> but the responses here seem to point to no Unix versions having this
> extension.
> --
> John Savage            (for email, replace "ks" with "k" and delete
"n")

I suggest you take a look at Eric Pement's Sed FAQ: this sort of
information is covered in detail there.  You can find it at:

http://www.faqs.org/faqs/editor-faq/sed/

HTH
--
Peter S Tillier
peter dot tillier at btinternet dot com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Wed, 07 Jan 2004 15:48:36 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. DDE Command reference for MS Office / MS Word

2. MS OUTLOOK, MS PROJECT replication.

3. MS SQL 7.0 vs. MS SQL 2000

4. Class(y) 2.4b, with documentation for MS-Word 97, MS-Word 6.0 and WordPerfect 7.0

5. How to use MS TreeView and MS ImageList

6. Haskell and MS-Excel, MS-Access

7. REXX for MS Windows 3.1 or MS WfWG 3.11

8. RexxGMSQ just released---IBM Object Rexx---MS SQL Server APIs for MS Windows NT

9. MS-COBOL 4.50 MS-Windows progs

10. MS Fortran DLL called from MS VB 6.0 problem

11. can't call MS Powerstation 4.0a DLL from MS VB 5 Pro

12. Compatibility of MS Fortran & MS VC 6.0

 

 
Powered by phpBB® Forum Software