It is currently Sun, 23 Nov 2014 07:46:32 GMT



 
Author Message
 add control characters using sed with escape sequences?
Ok, I've managed to pull out most of the hair on my head over this
one...

I want to do the opposite to what most people seem to be asking.  I
have an ascii text file on my unix server and I wish to add Ctrl-M
(^M) characters to the end of each line in the file.  There are no ^M
characters in the file presently.

I can do this rather easily using the following sed command,

  sed -e 's/$/^M/' infile > outfile

where ^M is entered as a control character using Ctrl-V + Ctrl-M.

However, what I need to do is create a script that does not contain
the control character ^M in the sed command.  I would like to use an
escape sequence for the ^M character so that my script does not
contain any control characters.

Is that possible using sed?  I have seen many posts that mention it is
hard to use escape sequences in sed.

An option might be to use the translate command "tr" however I have
had no luck using this command.

Help!?

Regards
Paul



 Sat, 29 Jan 2005 13:32:10 GMT   
 add control characters using sed with escape sequences?

I dont think so. You can use a scriptfile if you want avoid
control-characters on the command line (ie, sed -f <script-file> )

I think that "unix2dos" is doing what you want.

        bash$ echo "A string" > testfile

        bash$ od -c testfile
        0000000   A       s   t   r   i   n   g  \n
        0000011

        bash$ unix2dos testfile
        unix2dos: converting file testfile to DOS format ...

        bash$ od -c testfile
        0000000   A       s   t   r   i   n   g  \r  \n
        0000012

        bash$ echo -n "^M" >>testfile

        bash$ od -c testfile
        0000000   A       s   t   r   i   n   g  \r  \n  \r
        0000013

//Mats



 Sat, 29 Jan 2005 17:14:52 GMT   
 
   [ 2 post ] 

Similar Threads

1. Using sed with control/escape characters

2. mapping escape sequences to control characters in KSH

3. Escape sequences for color selection in character mode.

4. Insert escape sequence in file : SED ?

5. escape sequence characters

6. Escape sequence to flush characters

7. insert escape sequence in a file : SED ?

8. Escape sequences for display control??

9. escape characters with sed command

10. SED script character escape problems


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software