问题
How can I convert tabs to spaces in in all .js files in a directory in one command?
回答1:
find . -type f -iname "*.js" -print0 | xargs -0 -I _FILE_ tab2space _FILE_ _FILE_
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/18469830/how-do-i-convert-tabs-to-spaces-on-many-files-with-bash