仅将带有混合空格/制表符的 txt 文件转换为制表符(在可能的情况下) [英] convert txt file with mixed spaces/tabs to tabs only (where possible)

查看:27
本文介绍了仅将带有混合空格/制表符的 txt 文件转换为制表符(在可能的情况下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些包含混合制表符/空格的源代码文件,我想将其转换为一个文件,在该文件中,它自动将所有缩进空格替换为给定制表符空间长度的制表符(例如,制表符 = 2 个空格).

I have some source code file which has mixed tabs/spaces and I want to convert it to a file where it has automatically replaced all indentation spaces by tabs for a given tab space length (i.e. for example tab = 2 spaces).

任何简单的解决方案(使用常见的 Unix 工具、MacOSX、bash 或 zsh)?一些 sed 脚本或 Python 命令之类的?

Any easy solution (with common Unix tools, MacOSX, bash or zsh)? Some sed script or Python command or so?

谢谢,阿尔伯特

推荐答案

好的,给定的解决方案都没有让我满意,所以我自己编写了代码.:)

Ok, none of the given solutions satisfied me, so I coded it myself. :)

看这里:

这篇关于仅将带有混合空格/制表符的 txt 文件转换为制表符(在可能的情况下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆