Last active
June 14, 2023 06:05
-
-
Save rutgerhensel/cf76a3e09b63c2c4713723d4370d1d5e to your computer and use it in GitHub Desktop.
Find files, find contents in files, replace contents in files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # find all .env files and store in env_files.txt | |
| find . -name \.env -type f > env_files.txt | |
| # find oldstring in these files | |
| for i in `cat env_files.txt`;do | |
| grep -i "oldstring" $i | |
| done | |
| # find oldstring just with grep and no list of files | |
| grep -ir --include \.env "oldstring" | |
| grep -inr --include \.env "oldstring" | |
| # replace oldstring with newstring in these files | |
| for i in `cat env_files.txt`;do | |
| cat $i|sed s/^oldstring/newstring/g > $i.tmp | |
| mv $i.tmp $i | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment