为什么用空格而不是\ t的uniq -c输出? [英] Why uniq -c output with space instead of \t?

查看:139
本文介绍了为什么用空格而不是\ t的uniq -c输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用uniq -c一些文本文件. 其输出如下:

I use uniq -c some text file. Its output like this:

123(space)first word(tab)other things
  2(space)second word(tab)other things

....

所以我需要提取总数(如上面的123和2),但是我不知道如何去做,因为如果我按空格分割此行,它将喜欢这个['123', 'first', 'word(tab)other', 'things']. 我想知道为什么不使用tab输出?

So I need extract total number(like 123 and 2 above), but I can't figure out how to, because if I split this line by space, it will like this ['123', 'first', 'word(tab)other', 'things']. I want to know why doesn't it output with tab?

以及如何在shell中提取总数? (我终于用python,WTF提取了它)

And how to extract total number in shell? ( I finally extract it with python, WTF)

更新:抱歉,我没有正确描述我的问题.我不想对总数求和,我只想用(tab)替换(space),但它不会影响文字空间,因为我仍然需要后面的数据.就是这样:

Update: Sorry, I didn't describe my question correctly. I didn't want to sum the total number, I just want to replace (space) with (tab), but it doesn't effect the space in words, because I still need the data after. Just like this:

123(tab)first word(tab)other things
  2(tab)second word(tab)other things

推荐答案

尝试一下:

uniq -c | sed -r 's/^( *[^ ]+) +/\1\t/'

这篇关于为什么用空格而不是\ t的uniq -c输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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