Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Sep 2006
    Posts
    7

    Angry 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!!

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Can't you do a search and replace, using sed, awk, perl, emacs or something similar?

  3. #3
    Just 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!!

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I am not a expert
    It's time to become one.

    scroogle the following search terms:
    Code:
    bash tutorial
    and then these:
    Code:
    sed tutorial
    That way we don't have to spend time explaining things to you that others have already written.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just 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!

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    There's a difference between using single quotations marks (as you do here):
    Code:
    sed -e 's/$OLDSTARTADDR/$NEWSTARTADDR/' asv-2.temp
    sed -e 's/$OLDENDADDR/$NEWENDADDR/' asv-2.temp
    and double quotation marks. For example, if you run this script:
    Code:
    #!/bin/bash
    
    asdf=qwerty
    
    echo "$asdf"
    echo '$asdf'
    you'll get this output:
    Code:
    qwerty
    $asdf
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just 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!

  8. #8
    Linux 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|'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...