【问题标题】:tr not impacting file command outputtr 不影响文件命令输出
【发布时间】:2015-11-20 18:06:32
【问题描述】:

如果我跑:

$ ls -l /tmp
total 16
drwxr-xr-x   2 noaccess noaccess     177 Nov 18 09:53 hsperfdata_noaccess
drwxr-xr-x   2 root     root         117 Nov 18 09:53 hsperfdata_root

我得到了预期的结果:

]$ ls -l /tmp | tr -s '[:space:]'
total 16
drwxr-xr-x 2 noaccess noaccess 177 Nov 18 09:53 hsperfdata_noaccess
drwxr-xr-x 2 root root 117 Nov 18 09:53 hsperfdata_root

然而tr 不会影响file 的输出:

$ file /tmp/dummy
/tmp/dummy:     empty file

$ file /tmp/dummy | tr -s '[:space:]'
/tmp/dummy:     empty file

(如果我使用[:blank:],则相同)

我期待:

$ file /tmp/dummy | tr -s '[:space:]'
/tmp/dummy: empty file

我是不是在滥用filetr?我必须awk吗?我在 SunOS 5.10 上使用 bash 3.2.51,想区分 XML 和 gz 文件。

【问题讨论】:

    标签: file unix space trim tr


    【解决方案1】:

    file 的 Solaris 5.10 版本正在生成使用制表符而不是空格的输出:

    $ touch /tmp/dummy
    $ file /tmp/dummy | cat -vet
    /tmp/dummy:^Iempty file$
    $
    

    在这种情况下,tr -s 将单个制表符压缩为单个制表符...

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多