linux - 如何在 bash 中使用 tr 删除行首的所有空格

标签 linux bash unix sed tr

我知道用于从行首删除空格的 sed 语法,可以使用 tr 命令 完成吗?

我的文件是 file.txt 之类的。

    th ht djs
        ncdbh jdhbc ncbs 
     hi nc hdn 
 mued ndc 

从开头删除所有空格后,我们得到类似的文件

th ht djs
ncdbh jdhbc ncbs 
hi nc hdn 
mued ndc 

最佳答案

您问题的答案是tr 不支持使用正则表达式删除特定模式。 tr 的用途不同 - man tr

如果你想使用sed:

sed -i -e 's/^[ \t]*//' file.txt

关于linux - 如何在 bash 中使用 tr 删除行首的所有空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27540943/

相关文章:

linux - 如何在 Bash 中检测文件是否具有 UTF-8 BOM?

linux - 如何使 bash 中的 RETURN 陷阱保留返回码?

Linux :Scheduling backups

linux - 如何压缩 Bash 中的所有子文件夹?

mysql - 在 bash 中打印结构化 SQL SELECT 的简单方法

Bash:如何从输出中删除 xargs 产生的错误消息?

linux - linux中的top -c命令过滤基于进程名列出的进程

linux - x86 上的任务管理

linux - 如何使用 awk 提取引用字段?

bash - 读取 unix 上的文件列表并运行命令