[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: string replacement doesn't work with a variable



On 2/9/06, Marcel Fritzenwallner <linux fritzenwallner org> wrote:
> Thanks a lot!
>
> This little thing cost me many hours, now it's working even with "sed":
>
> sed -i "s/ABC/$VAR/" file.txt
> perl -pi'.bak' -e "s/ABC/$VAR/g" file.txt

Good deal. Just remember to be careful about what you expand the
variable to since that has the potential to mess up the syntax of the
perl or sed command. For example, if $VAR has a / character in it
mayhem will ensue.

More information about expansion of variables should be available in
the man page for the shell you are using too.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]