how do i convert tabs to spaces on many files with bash

强颜欢笑 提交于 2019-12-11 21:14:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!