Insert string in first column

2

I'm breaking my head with something very simple, I need to insert a ";" (semicolon) after a sort / uniq in a file. As the number of repeated rows returns, I need this return that is always in the first column to be inserted this ";". I already searched with "CUT, AWK, SED" and did not get a satisfactory result.

Example:

cat /tmp/filtrado2.txt|  sort| uniq -c| sort -nr

Thank you for helping me.

    
asked by anonymous 03.03.2017 / 20:32

2 answers

1

Just use a regular expression in sed to select any number: [0-9]+

In addition, using the & operator that retrieves the text that matched the search expression.

It would look like this:

cat /tmp/filtrado2.txt | sort | uniq -c | sort -nr | sed -r 's/[0-9]+/&;/'
    
03.03.2017 / 21:34
0

Try this:

cat /tmp/filtrado2.txt | sort | uniq -c | sort -nr | sed 's/1/1;/'
    
03.03.2017 / 21:09