-   Programming (
-   -   sed and variable (

chirophil91 10-18-2004 08:49 AM

sed and variable
I've some problem with variables between my bash script and sed:

The script is invoked like: my_file

Content of my_file:

blabla blabla blabla TopDesignName="old_pattern"

and i would like to have
blabla blabla blabla TopDesignName="new_pattern"

My bash script:

#I put the content of the last field ($NF) of the first record (NR<2) in #OLD_PATTERN variable (with " erased)
OLD_PATTERN=`awk -F "=" 'NR < 2 {print $NF} $1 | tr -d '\042'`
# and i want substitute the OLD_PATTERN by the NEW_PATTERN
cat $1 | sed "s/$OLD_PATTERN/NEW_PATTERN/" # don't work
#If I try
cat $1 | sed "s/old_pattern/NEW_PATTERN/" # work

So,I don't know how to pass the $OLD_PATTERN to sed ???

Thanks for your help

homey 10-18-2004 09:52 AM

Do you have to use a script and do you have to use sed?

awk -F= '{print$1"=new_pattern"}' file.txt > file1.txt

chirophil91 10-19-2004 03:23 AM


I think i have to use because the variable OLD_PATTERN is never the same,may be there is an easy solution
Thanks homey

All times are GMT -5. The time now is 06:32 PM.