LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   sed and variable (http://www.linuxquestions.org/questions/programming-9/sed-and-variable-244160/)

chirophil91 10-18-2004 08:49 AM

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

The script is invoked like:
script.sh 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:

#!/bin/bash
NEW_PATTERN="new_pattern"
#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
Philippe

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

Hi,

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:24 AM.