我使用 uniq -c 一些文本文件。
它的输出是这样的:
123(space)first word(tab)other things
2(space)second word(tab)other things
....
所以我需要提取总数(如上面的 123 和 2),但我不知道如何提取,因为如果我按空格分割这条线,它会像这样
['123', 'first', 'word(tab)other', 'things']
.我想知道为什么它不带标签输出?
以及如何在shell中提取总数? (我终于用python解压了,WTF)
更新 : 对不起,我没有正确描述我的问题。我不想对总数求和,我只想用(制表符)替换(空格),但它不会影响单词中的空格,因为我仍然需要之后的数据。像这样:
123(tab)first word(tab)other things
2(tab)second word(tab)other things
最佳答案
尝试这个:
uniq -c | sed -r 's/^( *[^ ]+) +/\1\t/'
关于shell - 为什么 uniq -c 输出带有空格而不是\t?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670393/