December 17, 2010

Linux Search & Replace Text in Directory Structure

Introduction

I have to perform a find and replace of text in files for an entire directory structure.  I do not do this often, so I have to look it up every time.  Unfortunately, it takes more time to look up than I would expect so here are some example.

Example #1
Find all files named "Root" and replace the text "FIND_ME" with the text "REPLACE_WITH"

find . -name Root -exec sed -i 's/FIND_ME/REPLACE_WITH/g' '{}' \;

No comments:

Post a Comment