On Sun, Oct 18, 2009 at 08:09:21PM +0200, Javier Barroso wrote: [...] > > I've just want to change on a file this line: > > > > vif = [ 'ip=167,112,134.223,mac=00:16:3E:FD:58:B8'] > > > > to: > > > > vif = ['ip=167,112,134.223,mac=00:16:3E:FD:58:B8,vifname=veth216','ip=10.1.1.1,mac=00:16:3E:FD:58:BB,vifname=veth216a'] > > > > AND, if it's possible to change tha last two entries of mac address, > > B8 to C8 for example.. > > sed -i '/^vif/s/B8.*$/C8,vifname=veth216'"'"','"'"'ip=10.1.1.1,mac=00:16:3E:FD:58:BB,vifname=veth216a'"'"']' > file.cfg > > As it is dificult to read see this explication: > If you want to use a ' inside replace string such is the case you must: > type ' to close string > Then type " to open a new concatenated string > type ' to write ' > type " to close the concatenated string > type ' to concatenate the next string (following with the replace > string) is it not clearer and easier to use double-quotes for the string and then just escape the single quotes? /tmp $ echo hello | sed "s/ll/l\'/" hel'o works just fine, and sed -i "/^vif/s/B8.*$/C8,vifname=veth216\',\'ip=10.1.1.1,mac=00:16:3E:FD:58:BB,vifname=veth216a\']" file.cfg seems, to me at least a little more readable. .02, ymmv etc. A
Attachment:
signature.asc
Description: Digital signature