tags:

views:

177

answers:

1

EDIT
i have something like this in a file:
imagecolor=0
arrayimagecolorcopy=0
arrayimagecolorcopy3d=0

when i use sed -i -e 's/imagecolor=0/imagecolor=1/' it will change 1 and 2 line. But i only want it to replace first line.
i also tried sed with \< \ > and \b \b, but no luck. Could it be the '=' sign? Do we have something like -w as in grep command?

Thank you.

+2  A: 

It seems to work for me:

$ echo 'imagecolor=0
> imagecolorcopy=0
> imagecolorcopy3d=0' > input.txt

$ sed -i -e 's/imagecolor=0/imagecolor=1/' input.txt

$ cat input.txt
imagecolor=1
imagecolorcopy=0
imagecolorcopy3d=0

If you only want to make the substitution when the entire line matches, try anchoring your regular expression:

$ sed -i -e 's/^imagecolor=0$/imagecolor=1/' input.txt
Mark Byers
sorry, i made an edit.
rashid
if i pass imagecolor to a function can i do this within my function:sed -i -e 's/^$1=0$/$1=1/' input.txt
rashid
@rashid, Yes but you'd need double quotes, not single quotes. By the way, is your original problem solved?
Mark Byers
yes Mark thanks aloooooot!!!! i have been working like for 3 hours, wew!!! I am gonna get some coffee now. thanks again. Works like a charm.
rashid