0

In the script below second & third line are working but not the first and fourth. The reason is because I am replacing the whole line, I actually only need to replace what's to the right of the '=' sign. Any idea on how I can accomplish this in sed? Thanks.

# example: ./configure input-file, SSID, IP, device-name, gateway, frequency
#
#
FILE=${1}
SSID=${2}
IP=${3}
DEVICE=${4}
GATEWAY=${5}

sed -e "s/\(wireless\.1\.ssid=\).*/${SSID}/g"           \
    -e "s/192\.168\.1\.20$/${IP}/g"                     \
    -e "s/\(NanoBridge M.\)/${DEVICE}/g"                \
    -e "s/\(route\.1\.gateway=\).*/${GATEWAY}/g" ${FILE} > /home/garrett/Desktop/NEW-CONFIG.txt
#END#
2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by djbobyd
0

I am not very good with sed as well, but what always helps me in this case is google :)
here is an example I just found there:

This will replace /tmp/tmp/... with aaa:

$ sed 's/(.=)[^ ] (.*)/\1 aaa \2/g' <<< "-Djava.util.logging.config.file=/tmp/tmp/tmp/config bla.bla"
-Djava.util.logging.config.file= aaa bla.bla
It "saves" anything up to = in \1. Then fetches everything up to an space. Finally "saves" the rest of the string in \2.

The replacement is done by echoing \1 + "new string" + \2.

It seems closest to your problem. Hope it helps rewriting your own lines. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.