This file contains 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
# https://stackoverflow.com/questions/18046456/excluding-a-directory-from-find-and-sed-rename | |
# https://stackoverflow.com/questions/9704020/recursive-search-and-replace-in-text-files-on-mac-and-linux | |
find app -type f -name '*.erb' -not \( -path 'app/views/helpers/*' \) -exec sed -i '' s/this/that/ {} + | |
# Given a file `sel` of strings, remove all instances of them in all other directories | |
for i in `cat sel` ; do echo $i | cut -c2- | find app -type f -name '*.erb' -not \( -path 'app/views/helpers/*' \) -exec sed -i '' "s/$i//" {} +; done |
This file contains 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
# Assumes two files present (`sel` and `filez`) | |
# OSX needs an empty zero length argument, which is quite difficult to escape if using the same type of quotations | |
# Inner file (`filez`) is used over a `find ... -exec` to cut down on repetitive operations | |
cat sel | xargs -I '{}' sh -c 'cat filez | xargs sed -i "" "s/{}//"' |
This file contains 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 app/assets -type f -name '*.scss' | sed -E 's|/[^/]+$||' | sort -u |
This file contains 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
const childProcess = require('child_process'); | |
function runShell(cmd, args, options) { | |
const output = childProcess.spawnSync(cmd, args, options); | |
return output.stdout.toString(); | |
}; | |
// 1. With just the base command | |
const findCmd = `find app/assets -type f -name *.js -not \( -path *spec* \) -o -name *.coffee -not \( -path *spec* \)`; |
This file contains 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
# Inspired by https://unix.stackexchange.com/questions/72739/how-to-remove-multiple-blank-lines-from-a-file | |
for i in `grep -rl classSelector app/assets/stylesheets/` ; do cat $i | awk '!NF {if (++n <= 1) print; next}; {n=0;print}' | tee $i; done |
This file contains 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
# Inspired by Stack Overflow Question 19151954 | |
LINE_NO = `grep -n require $1 | tail -1 | cut -d: -f1` | |
sed ''"${LINE_NO}"' a \ | |
text_to_add | |
' $1 |
This file contains 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
# Get list of all files | Print out each line count | Remove final line total | Calculate average | |
find . -name *.scss | xargs wc -l | sed -e '$ d' | awk '{ total += $1; count++ } END { print total/count }' |
This file contains 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
grep -lr \.coffee app/assets/ | xargs sed -i '' -e '/\.\./!s/coffee/js/g' |
This file contains 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
seq 20 | xargs -I{} echo "Hi there {}" |
OlderNewer