Project

General

Profile

Feature #640

Using Sed To Replace a String In Multiple Files

Added by Daniel Curtis over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Development Environment
Target version:
Start date:
08/14/2015
Due date:
% Done:

100%

Estimated time:
0.10 h
Spent time:

Description

This is a guide for using the sed utility to replace a string in multiple files.

  • Switch to the working folder to run the command in:
    cd /usr/local/www/
    
  • Then use sed to replace all instances of foo with bar in all files in the working directory:
    sed -i 's/foo/bar/g' *
    
  • Alternatively, if there are folders in the working directory you may want to recirsively find all files and apply the replacement to them. This can be accomplished by running:
    find . -type f -exec sed -i 's/foo/bar/g' {} ;
    

Resources

#1

Updated by Daniel Curtis over 8 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100
#2

Updated by Daniel Curtis over 8 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF