I have a file strings.txt
listing strings, which I am processing like this:
sort strings.txt | uniq -c | sort -n > uniq.counts
So the resulting file uniq.counts
will list uniq strings sorted in the ascending order by their counts, so something like this:
1 some string with spaces
5 some-other,string
25 most;frequent:string
Note that strings in strings.txt
may contain spaces, commas, semicolons and other separators, except for the tab. How can I get uniq.counts
to be in this format:
1<tab>some string with spaces
5<tab>some-other,string
25<tab>most;frequent:string
You can do:
sort strings.txt | uniq -c | sort -n | sed -E 's/^ *//; s/ /\t/' > uniq.counts
sed
will first remove all leading spaces at the beginning of the line (before counts) and then it will replace space after count to tab
character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With