BSD (including Mac OS X) version of sed
is not GNU's one, including a subtle difference with in-place remplacements.
On BSD systems, you HAVE TO replace occurrence of sed -i -e
with sed -i '' -e
to make it work.
find -name '*.js'|grep -v '^./node_modules'|while read f;do if (head -n3 "$f"|grep -Fv 'use strict'>/dev/null);then echo "$f";sed -i -e '1i "use strict"\n' "$f";fi;done |
alias rigid="find -name '*.js'|grep -v '^./node_modules'|while read f;do if (head -n3 \"\$f\"|grep -Fv 'use strict'>/dev/null);then echo \"\$f\";sed -i -e '1i \"use strict\";\\n' \"\$f\";fi;done" |
find -name '*.js' `# Find all .js files in current directory, recursively` | \ | |
grep -v '^./node_modules' `# Exclude node_modules folder, you may want to add additional folders here` | \ | |
while read f; do | |
if (head -n3 "$f" | grep -Fv 'use strict' > /dev/null); then `# Check first three lines, thought about shebang` | |
echo "$f" | |
sed -i '1i "use strict"\n' "$f" `# Prepend "use strict", that may break your executable scripts` | |
fi | |
done |
BSD (including Mac OS X) version of sed
is not GNU's one, including a subtle difference with in-place remplacements.
On BSD systems, you HAVE TO replace occurrence of sed -i -e
with sed -i '' -e
to make it work.
@rex, you are my hero :) Your final command has server me quite a bit.
Set it to use
-n8
, for our use case. (Comments come before use strict, though I guess it makes sense to see 'use strict' as the first line) Worked perfectly!