Skip to content

Instantly share code, notes, and snippets.

@jeiea
Created September 28, 2020 04:16
Show Gist options
  • Save jeiea/0fbab1eba87df53b8e8abbce26223458 to your computer and use it in GitHub Desktop.
Save jeiea/0fbab1eba87df53b8e8abbce26223458 to your computer and use it in GitHub Desktop.
Substitute string from all path
# You shouldn't execute this if you didn't read it.
# If not installed
brew install sd
# Not effective commands
find . -ipath '*apple*' -type f | tac > source.txt
cat source.txt | sd 'apple' 'banana' | sd 'Apple' 'Banana' > dest.txt
paste -d" " source.txt dest.txt > replace.txt
# Effective commands
cat dest.txt | sd '.+' 'mkdir -p `dirname $0`' | zsh
cat replace.txt | sd '(\S+) (\S+)' 'mv $1 $2' | zsh
find . -ipath '*apple*' -exec rm -rf {} \;
rm source.txt dest.txt replace.txt
# For checking path completely removed
# find . -ipath '*apple*'
# For reverting changes
# find . -ipath '*banana*' -exec rm -rf {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment