Using sed with control/escape characters

Using sed with control/escape characters

Post by Bria » Fri, 12 Jul 2002 21:55:55



The following statement works fine when entered from a Unix command
line:

sed 's/^L//' oldfile >newfile  (where the ^L was composed with a Ctrl V
and Ctrl L key sequence)

However, when I copy this into a script (#!/bin/sh) it does not work
(i.e. it does not remove all the ^L in the file)

I have also tried sed 's/\cL//' and sed 's/\014//' but they don't work
from the command line or in the script.

Thanks for helping.

 
 
 

Using sed with control/escape characters

Post by Bill Marc » Fri, 12 Jul 2002 23:24:27


On Thu, 11 Jul 2002 08:55:55 -0400,

>The following statement works fine when entered from a Unix command
>line:

>sed 's/^L//' oldfile >newfile  (where the ^L was composed with a Ctrl V
>and Ctrl L key sequence)

>However, when I copy this into a script (#!/bin/sh) it does not work
>(i.e. it does not remove all the ^L in the file)

It should work in a script.  If you edit the script with vi, you can use
the same ctrl V ctrl L keys.

Quote:>I have also tried sed 's/\cL//' and sed 's/\014//' but they don't work
>from the command line or in the script.

You could use tr -d '\014'

 
 
 

Using sed with control/escape characters

Post by CornĂ© Beers » Fri, 12 Jul 2002 23:40:56



> The following statement works fine when entered from a Unix command
> line:

> sed 's/^L//' oldfile >newfile  (where the ^L was composed with a Ctrl V
> and Ctrl L key sequence)

> However, when I copy this into a script (#!/bin/sh) it does not work
> (i.e. it does not remove all the ^L in the file)

> I have also tried sed 's/\cL//' and sed 's/\014//' but they don't work
> from the command line or in the script.

In my .login script I define several of such frequently used control
characters like for the escape character: 'setenv ESC <esc>'. Then in
the lines I can use the variables in place.

Works great and is even usable with cut-n-paste over terminals.

It's a little tricky in sed and such lines. To have an example, replace
escape characters with __ESC__ to debug some output:
sed 's/'"${ESC}"'/__ESC__/g'

CBee

 
 
 

Using sed with control/escape characters

Post by those who know me have no need of my nam » Thu, 18 Jul 2002 22:29:35


in comp.unix.shell i read:

Quote:>The following statement works fine when entered from a Unix command
>line:

>sed 's/^L//' oldfile >newfile  (where the ^L was composed with a Ctrl V
>and Ctrl L key sequence)

if more than one line-feed were on a line this sed script would only remove
the first, because you didn't use the `g' modifier.

Quote:>However, when I copy this into a script (#!/bin/sh) it does not work
>(i.e. it does not remove all the ^L in the file)

when you `copied' it into the script are you sure that the ^L remained a
single line-feed character instead of the two printing characters ^ and L?

--
bringing you boring signatures for 17 years

 
 
 

1. 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

2. export boottime gdt from i386/kernel/trampoline.S

3. SED script character escape problems

4. Problem with timezone and netscape

5. escape characters with sed command

6. e2fsck 0.4b and pl15

7. Questions regarding recognizing control/escape characters.

8. What exactly is the CD ROM a month offer ?

9. Apache: escaping control characters in logs

10. mapping escape sequences to control characters in KSH

11. ZMODEM version differences; Escape Control Characters

12. Escape character control

13. looking for an escape function (ansi c) to escape characters for usage in an URL