replacing the special '$' in sed or vi

replacing the special '$' in sed or vi

Post by siu_j.. » Sat, 31 Jul 1999 04:00:00



Hi everyone,
  I have a text file that has the '$' character in it and want to
replace it with something else using a script.  sed and vi treats it as
a special character.. I can get around it in vi by using \ in front of
it, but not in sed.  Can anyone please tell me how to do it in sed or
how to use vi in a script?

thanks,
  -- john

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

replacing the special '$' in sed or vi

Post by Charles Dem » Sat, 31 Jul 1999 04:00:00



>Hi everyone,
>  I have a text file that has the '$' character in it and want to
>replace it with something else using a script.  sed and vi treats it as
>a special character.. I can get around it in vi by using \ in front of
>it, but not in sed.  Can anyone please tell me how to do it in sed or
>how to use vi in a script?

sed -e 's/\$/#/' infile

would change the first $ to #

sed -e 's/[$]/#/' infile

would also work

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.


 
 
 

replacing the special '$' in sed or vi

Post by Kurt J. Lanz » Sat, 31 Jul 1999 04:00:00



> Hi everyone,
>   I have a text file that has the '$' character in it and want to
> replace it with something else using a script.  sed and vi treats it as
> a special character.. I can get around it in vi by using \ in front of
> it, but not in sed.  Can anyone please tell me how to do it in sed or
> how to use vi in a script?

Why not in sed? If the entire sed command is enclosed in single quotes
(the normal case, "man sh" and see the shell's quoting rules for why),
a backslash should hide a $ from sed's normal interpretation and cause
it to be treated like a normal character.
 
 
 

replacing the special '$' in sed or vi

Post by Ed All » Tue, 03 Aug 1999 04:00:00



>Hi everyone,
>  I have a text file that has the '$' character in it and want to
>replace it with something else using a script.  sed and vi treats it as
>a special character.. I can get around it in vi by using \ in front of
>it, but not in sed.  Can anyone please tell me how to do it in sed or
>how to use vi in a script?

Since everyone else dealt with sed I will talk about vi.

Try:

$> vi filename <change-dollar

Where change-dollar looks like:

:%s/\$/#/g
:wq

Although the : in front of each line just switches from vi-mode
to ex-mode.  You can avoid the : and not flash your screen as
the commands run by invoking ex instead of vi:

$> ex filename <change-dollar

At least one other way exists but this is the easiest to grasp.

                        Ed Allen