Alex Rivera | Logout

Why uniq -c output with space instead of \t?

Asked 2012-07-26T13:29:41.590
8

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

....

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?

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

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
Edit
Report

1 Answer

0
$ cat <file> | uniq -c | awk -F" " '{sum += $1} END {print sum}'
answered 2012-07-26T13:38:14.420

Your Answer