LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-03-2011, 01:25 AM   #1
moata_u
Member
 
Registered: Jan 2011
Posts: 32

Rep: Reputation: 0
Smile 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\racle\:thin\:@$ipnumber\:1521\:billz" # new line
echo `sed "s/'${find}'{/'${input}'{/g" application.properties` # replace line
 
Old 03-03-2011, 01:53 AM   #2
moata_u
Member
 
Registered: Jan 2011
Posts: 32

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by moata_u View Post
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\racle\: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****
-------------------------------------------------------------------------------------
 
Old 03-03-2011, 07:31 AM   #3
moata_u
Member
 
Registered: Jan 2011
Posts: 32

Original Poster
Rep: Reputation: 0
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=jdbcracle:thin:@$ipnum:1521:e"
sed -i "s/"$find"/"$test"/g" application.properties
 
Old 03-03-2011, 08:12 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,689

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
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
 
  


Reply

Tags
shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 08:59 AM
sed: how to change MAC address string with sed cold Linux - Software 5 08-02-2010 08:43 AM
Problem with sed lemon09 Programming 8 01-29-2010 09:07 AM
Sed Problem Hydrap Linux - Newbie 1 04-26-2006 04:41 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration