LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 12: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, 12: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, 06: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, 07:12 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

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



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 07:59 AM
sed: how to change MAC address string with sed cold Linux - Software 5 08-02-2010 07:43 AM
Problem with sed lemon09 Programming 8 01-29-2010 08:07 AM
Sed Problem Hydrap Linux - Newbie 1 04-26-2006 03:41 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:33 PM.

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
Open Source Consulting | Domain Registration