Results 1 to 8 of 8
Hello Folks!!
I am having problem changing values on my files, let me explain:
I have a file called asv-1.txt, but inside this file a have a values ( I ...
- 12-08-2008 #1Just Joined!
- Join Date
- Sep 2006
- Posts
- 7
Changing Value
Hello Folks!!
I am having problem changing values on my files, let me explain:
I have a file called asv-1.txt, but inside this file a have a values ( I use cat to get the values and send them to my email).
inside asv-1.txt I have this
<value>1.255.0.1</value>
I have more code than that, I am trying to use asv-1.txt as a template, but I havent figure out how to change the 1.255.0.1 value for a completly diffrent value... I dont want to do it manually, the value comes from another source (mysql) and I dont have any problem getting the value from my db, but how do I change the value without doing everything from scratch?
I need this for a report, and asv-1.txt already has all the info that I want.
Please help!!
Thanks!!
- 12-09-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Can't you do a search and replace, using sed, awk, perl, emacs or something similar?
- 12-09-2008 #3Just Joined!
- Join Date
- Sep 2006
- Posts
- 7
I dont have any problem using other language instead of using bash, but do you guys can help me out? I am not a expert, I barely use bash.
let say that I want to change this
<value>1.255.250.1</value>
for this
<value>72.34.34.1</value>
thank you for your help!!
- 12-09-2008 #4It's time to become one.I am not a expert
scroogle the following search terms:
and then these:Code:bash tutorial
That way we don't have to spend time explaining things to you that others have already written.Code:sed tutorial
--
Bill
Old age and treachery will overcome youth and skill.
- 12-09-2008 #5Just Joined!
- Join Date
- Sep 2006
- Posts
- 7
thank you for you response.
I am using bash and sed, but I cannot make it work, here is my script.
#!/bin/bash
NEWSTARTADDR=`cat newaddress | grep '<start>'`
NEWENDADDR=`cat newaddress | grep '<end>'`
OLDSTARTADDR=`cat asv-2.temp | grep '<start>'`
OLDEDNADDR=`cat asv-2.temp | grep '<ed>'`
sed -e 's/$OLDSTARTADDR/$NEWSTARTADDR/' asv-2.temp
sed -e 's/$OLDENDADDR/$NEWENDADDR/' asv-2.temp
The bash works, I got the values on my variables ( I added echo $newstartaddr and I got the right resonse) but for whatever reason, sed is not taking those values, I know I missing something but I dont know what ist.
Thanks!
- 12-09-2008 #6
There's a difference between using single quotations marks (as you do here):
and double quotation marks. For example, if you run this script:Code:sed -e 's/$OLDSTARTADDR/$NEWSTARTADDR/' asv-2.temp sed -e 's/$OLDENDADDR/$NEWENDADDR/' asv-2.temp
you'll get this output:Code:#!/bin/bash asdf=qwerty echo "$asdf" echo '$asdf'
Code:qwerty $asdf
--
Bill
Old age and treachery will overcome youth and skill.
- 12-09-2008 #7Just Joined!
- Join Date
- Sep 2006
- Posts
- 7
I have changed to double quotation, and now I am getting this error:
<start>1.255.100.20</start> - old start adddress
<end>1.255.100.20</end> - old end address
<start>This is a new START value</value> - new start address
<end>This is a new END value</end> - new end address
sed: -e expression #1, char 32: unknown option to `s'
sed: -e expression #1, char 28: unknown option to `s'
<end>This is a new END value</end>
<end>1.255.100.20</end>
Here is my change
sed -e "s/$OLDSTARTADDR/$NEWSTARTADDR/" asv-2.temp
sed -e "s/$OLDENDADDR/$NEWENDADDR/" asv-2.temp
thansk!
- 12-10-2008 #8Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
The problem here is that the "s" command uses slashes as argument separators by default. Your arguments contain slashes, however. You can avoid this problem by using some other character as argument separator, like this:
Code:sed 's|///|abc|'


Reply With Quote