Need help with search/replace using grep/sed
Hello,
I have another grep problem! This time i'm trying to search/replace an image file name throughout multiple files recursively. I've gotten this far:
grep -l "littlecampaignlogo" 2009/*/*.html | xargs sed -i 's/littlecampaignlogo.gif/littlecampaignlogo2009.gif'
The problem is what to do with the . in the file name? Sed is returning an error.
Thanks for any help!!
P.S. It would be great if someone could write an article on some of these commands for A Padded Cell!
Greg K posted this at 21:16 — 1st November 2010.
He has: 2,145 posts
Joined: Nov 2003
I think you just need to escape the . with backslash.
's/littlecampaignlogo\.gif/littlecampaignlogo2009\.gif'
Megan posted this at 15:14 — 2nd November 2010.
She has: 11,421 posts
Joined: Jun 1999
Thanks, Greg. If I do this:
grep -l "littlecampaignlogo" 2009/*/*.html | xargs sed -i 's/littlecampaignlogo\.gif/littlecampaignlogo2009\.gif'
It gives me the error "sed: -e expression #1, char 53: unterminated `s' command"
Megan
Connect with us on Facebook!
Megan posted this at 16:26 — 2nd November 2010.
She has: 11,421 posts
Joined: Jun 1999
Stupid error, just needed a closing slash on the sed command:
grep -l "littlecampaignlogo" 2009/*/*.html | xargs sed -i 's/littlecampaignlogo\.gif/littlecampaignlogo2009\.gif/'
Megan
Connect with us on Facebook!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.