Labels

tools (7) programming (6) rails (5) cluj (4) productivity (4) misc (3) startups (3) emberjs (2) internet (2) software (2) hack (1) meetup (1) os x (1) science (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 :)

No comments:

Post a Comment