Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am migrating my blog, and all the posts have metadata at the top of the file. As a result I have a group of nearly 100 files in a directory where I want to do a search and replace for:

^permalink: http://blog.olddomain.com/(.*)$

to

permalink: http://blog.newdomain.com/$1

in all 100 files.

What commands would I use to do this?

share|improve this question
    
possible duplicate of Search and replace in multiple files based on condition –  Gilles May 31 '11 at 12:01

1 Answer 1

up vote 3 down vote accepted

sed is often used to pipe something through it, but it can process files just as well and, with the -i option, can even change them in place.

sed -i 's|^\(permalink: http://blog\.\)olddomain\(\.com/.*\)$|\1newdomain\2|g' <shell-glob-pattern>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.