A SED script

Warren Block wblock at wonkity.com
Sat Jun 26 12:38:12 PDT 2004


On Sat, 26 Jun 2004, antenneX wrote:

> Running FBSD-4.10
>
> Below is a portion of a script that uses sed(1) to change a portion of a
> line in a file. It works fone for that one.
>
> However, I cannot get it to work on another file (perl.pl file) to
> change the line:
> $OrderNumPrefix = "ATX060"; to $OrderNumPrefix = "ATX070";
>
> I suspect I'm not handling the quotes or other operators correctly and
> it just ignores the change.
>
> Here's the snippet of the script I'm trying to use:
> #!/bin/sh
> new=`grep -i new /path/to/newfile`
> old=`grep -i new /path/to/oldfile`
> sed -i.bak -e "s/$old/$new/" /path/to/myfile
>
> ....and, again the line in the file:
> $OrderNumPrefix = "ATX060"; <---line in the file to change
>
> What do I need to change to make it work....???

You don't show what changes you have made to the program.  A first guess 
is that you aren't escaping quotes.  If you insert an "echo" command 
before the sed command, you'll be able to see what is actually going on. 
You may get away with just changing the sed pattern delimiter, say to 
something like a "%" sign.

-Warren Block * Rapid City, South Dakota USA


More information about the freebsd-questions mailing list