Coderwall
Ruby Python JavaScript Front-End Tools iOS
More Tips
Ruby Python JavaScript Front-End Tools iOS PHP Android .NET Java Jobs
Jobs
Sign In or Up
Last Updated: February 25, 2016
·
23.1K
· rhumlover

Grep and replace text in files

#terminal
#sed
#grep
#linux
#replace
#macos

Linux

grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'

MacOS

grep -rl matchstring somedir/ | xargs sed -i '' 's/string1/string2/g'

@see http://stackoverflow.com/a/4247319

Source: http://vasir.net/blog/ubuntu/replace_string_in_multiple_files

#terminal
#sed
#grep
#linux
#replace
#macos

Written by Thomas LE JEUNE

Say Thanks
Respond

Related protips

Use ⌥ ← and ⌥→ to jump forwards / backwards words in iTerm 2, on OS X

338.2K
46

Determine OS X version from the command line

132.3K
1

Customize terminal with oh-my-zsh

74.05K
3

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Best #Terminal Authors
e-dard
337.8K
#terminal
#Python
#Shell
kevinelliott
132.2K
#terminal
#ruby
#ios
itseranga
113.8K
#terminal
#cryptography
#docker
rawswift
66.11K
#terminal
#PHP
#Pascal
mikker
63.11K
#terminal
#Ruby
#Objective-C
Related Tags
#terminal
#sed
#grep
#linux
#replace
#macos
Sponsored by
#native_company#
#native_desc#
#native_cta#
Filed Under

Tools
Awesome Job
See All Jobs

Post a job for only $299
Thanks to our sponsor
Sponsored by #native_company# — Learn More
#native_title# #native_desc#
#native_cta#
@coderwall
APM product comparisons Contact Privacy Terms

Copyright 2025

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.