Labels

tools (7) programming (5) cluj (4) misc (4) rails (4) productivity (3) startups (3) internet (2) meetup (2) software (2) emberjs (1) hack (1) science (1) zencash (1)

Friday, July 27, 2012

sed replace inside quotes



Here's a useful sed one-liner:

echo "printf(\"foo\");" > quotemeonthat
sed -i.bak 's/printf("\(.*\)")/printf("\1 is just too lonely without bar")/' quotemeonthat
cat quotemeonthat 

-i.bak - edits the file, preserving the original in quotemeonthat.bak
\1 - refers to the first matched group

output:
printf("foo is just too lonely without bar");

Suggestions for improvements are always welcome :)