Reputation: 189
suppose a file that contains:
a=1234
b=5678
c=word
i am writing a bash script that will change a's value. i use following command:
echo `sed "s/\(a=\).*/\1 new/" file` >file
it gives:
a=new b=5678 c=word
i also tried following (using anchors) still getting same format:
echo `sed "s/\(a=\).*[\n]$/\1 new/" file` >file
echo `sed "s/\(a=\).*'\n'$/\1 new/" file` >file
where i want:
a=new
b=5678
c=word
how to do that?
Upvotes: 1
Views: 479
Reputation: 133528
You could a following sed too once.
sed -i '/^a=/s/=.*/=new/g' Input_file
Upvotes: 0
Reputation: 22831
Use the -i
argument to edit the file in place:
sed -i 's/\(a=\).*/\1new/' file
Upvotes: 2