Reputation: 21801
How can I convert tabs to spaces in in all .js files in a directory in one command?
Upvotes: 0
Views: 463
Reputation: 12316
Simpler syntax:
for F in *.js; do sed -iE 's|\t| |g' $F; done
(Caution, edits files in place.) Could be made to rename edited copy, or placed into a function if you do this often.
Upvotes: 0
Reputation: 75548
This would convert tabs to four spaces:
find /path/to/directory -type f -iname '*.js' -exec sed -ie 's|\t| |g' '{}' \;
Change the space part in sed between the next two |
to have a custom number of spaces you like.
Another way is to process all files to one sed call at once with +
:
find /path/to/directory -type f -iname '*.js' -exec sed -ie 's|\t| |g' '{}' '+'
Just consider the possible limit of arguments to a command by the system.
Upvotes: 1
Reputation: 21801
find . -type f -iname "*.js" -print0 | xargs -0 -I _FILE_ tab2space _FILE_ _FILE_
Upvotes: 1