linux - 如何在 linux 中删除两个连续选项卡中的一个选项卡

标签 linux shell

我有一个文件,其中所有列都用制表符分隔。在某些地方,两个或多个选项卡连续出现。所以我想在两个或更多选项卡中保留一个选项卡。输入文件如下-

10517-akr   0   0   0   0   0   0   0   0
10518-akr       0   0   0   1   0   0   0
10515-akr   0   0   0   0   4   0   0   0
10514-akr           0   1   17  0   0   0
10513-akr   0   0   0   0   1   0   0   0

期望的输出是-

10517-akr   0   0   0   0   0   0   0   0
10518-akr   0   0   0   1   0   0   0
10515-akr   0   0   0   0   4   0   0   0
10514-akr   0   1   17  0   0   0
10513-akr   0   0   0   0   1   0   0   0

最佳答案

您可以使用 tr 将多个重复的选项卡压缩为一个:

tr -s '\t' < inputfile > outfile

引用man tr:

   -s, --squeeze-repeats
          replace each input sequence of  a  repeated  character  that  is
          listed in SET1 with a single occurrence of that character

关于linux - 如何在 linux 中删除两个连续选项卡中的一个选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20539937/

相关文章:

shell - Makefile 可以依赖于 shell 脚本的结果吗?

linux - 比较unix中的两个文件并将增量添加到一个文件中

linux - 将带有空列的行添加到制表符分隔文件

mysql - 无法使用 HeidiSQL : "Can' t connect to MySQL server on 'localhost' "连接到 Vagrant

c++ - Boost CRC 和 linux/lib/crc-ccitt.c 的区别

使用 win 7 本地凭据的 linux smbclient

shell - 使用单行 shell 命令替换所有文件中的特定文本

Linux命令了解系统配置

linux - Debian 11 (bullseye) 上的 "The repository does not have a Release file"错误,即使存储库有 Release 文件

macos - 操作系统 : tree -I command error opening dir