Skip to content

Instantly share code, notes, and snippets.

@rutgerhensel
Last active June 14, 2023 06:05
Show Gist options
  • Select an option

  • Save rutgerhensel/cf76a3e09b63c2c4713723d4370d1d5e to your computer and use it in GitHub Desktop.

Select an option

Save rutgerhensel/cf76a3e09b63c2c4713723d4370d1d5e to your computer and use it in GitHub Desktop.
Find files, find contents in files, replace contents in files
# 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