Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/(.*)$


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
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


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.