简体   繁体   English

如何使用相应的空格字符数替换制表符? (在linux中)

[英]How do I replace a tab character with the corresponding number of space characters? (in linux)

I am planning on replacing all of my tab characters in a certain file with the corresponding number of space characters in a shell. 我打算用一个shell中相应数量的空格字符替换某个文件中的所有制表符。 Tried using tr and sed, but none seem to work out. 尝试使用tr和sed,但似乎都没有成功。 Any suggestions? 有什么建议么?

Have you tried expand ? 你试过扩展吗? Usage is: 用法是:

$ expand  <FILE_WITH_TABS> > <FILE_WITH_NO_TABS>

You can also modify tab width using -t option. 您还可以使用-t选项修改选项卡宽度。 For example, to change from the default width to 2: 例如,要从默认宽度更改为2:

$ expand -t 2 <FILE_WITH_TABS> <FILE_WITH_NO_TABS>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM