LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   sed....problem (http://www.linuxquestions.org/questions/programming-9/sed-problem-866140/)

moata_u 03-03-2011 01:25 AM

sed....problem
 
hello there ...

am facing problem in sed command , i was trying write a bash script that do the following : search for the line that contain :@ , then save the line that contain and replace it with another line ....as following :

#! /bin/bash

echo "Please enter the ip address of you file"
read ipnumber
find=`grep ':@' application.properties` # find the line
input="connection.url=jdbc\:oracle\:thin\:@$ipnumber\:1521\:billz" # new line
echo `sed "s/'${find}'{/'${input}'{/g" application.properties` # replace line

moata_u 03-03-2011 01:53 AM

Quote:

Originally Posted by moata_u (Post 4277287)
hello there ...

Am facing problem in sed command , i was trying write a bash script that do the following : Search for the line that contain :@ , then save the line that contain and replace it with another line ....as following :

#! /bin/bash

echo "please enter the ip address of you file"
read ipnumber
find=`grep ':@' application.properties` # find the line
input="connection.url=jdbc\:oracle\:thin\:@$ipnumber\:1521\:billz" # new line
echo `sed "s/'${find}'{/'${input}'{/g" application.properties` # replace line

-----------------------------------------------------------------------------------
******the problem is the file still the same ******nothing change****
-------------------------------------------------------------------------------------

moata_u 03-03-2011 07:31 AM

my problem was : i was using an variable name (value) ,, which is reserved :))
Solution is :
!/bin/bash

read -p "Please Enter The ip address : " ipnum
find=grep ":@" application.properties
test="connection.url=jdbc:oracle:thin:@$ipnum:1521:e"
sed -i "s/"$find"/"$test"/g" application.properties

grail 03-03-2011 08:12 AM

Quote:

my problem was : i was using an variable name (value) ,, which is reserved )
You mean like using application names like 'find' or 'test'? If you must use these types of names you will find it much safer to capitalise the word so there is no confusion.

Also, no need to go in and out of quotes:
Code:

#current
sed -i "s/"$find"/"$test"/g" application.properties

#alternative
sed -i "s/$find/$test/g" application.properties



All times are GMT -5. The time now is 11:00 AM.