i'm trying search , replace string in file on mac terminal using sed. i'm able search , replace simple string:
sed -i.bak 's/hosts/boasts/g' file.txt
but i'm trying on little more complicated, string want replace looks 'hosts:"123.123.123.123, 12345"' - 123.123.123.123
being variable ip can't search that, i'm trying use regular expressions, "." indicate don't know ip address be.
i've tried following no luck:
sed -i.bak 's/hosts:"., 00000"/hosts:"999.999.999.999, 00000"/g' file.txt
you try following:
echo "hosts:\"123.123.123.123, 12345\"" | sed -e 's/[0-9][0-9][0-9]\.[0-9][0-9][0-9]\.[0-9][0-9][0-9]\.[0-9][0-9][0-9]/999.999.999.999/g'.
each [0-9]
digit, , each \.
actual symbol, not "match character" symbol on sed. assumes ips have structure. if you're dealing xxx.xxx.xxx.xxx:xxxx
you'll have edit accordingly.
Comments
Post a Comment