I want to replace all multiple tabs with a single tab with sed. I am trying to use
sed 's:\t+:\t:' .\text.CSV > newtext.csv
but this doesn't seem to work
If I open in sublime and replace by regex all \t+
to \t
it works properly
what is wrong with my sed?
Also, if I replace tabs with a comma with
sed 's:\t\t*:,:g' text.CSV > newtext.csv
I get this kind of line
264262360,20030826,200308,2003,2003.6466,BUS,EMPLOYER,,,,,,BUS,,, ,,,,,,,,,,0,051,051,05,1,3.4,12,2,12,5.24866163479182,1
sed s/ */ /g This will replace any number of spaces with a single space. sed s/ $// This will replace any single space at the end of the line with nothing. sed s/ /,/g This will replace any single space with a single comma.
You can also use tr
to replace multiple tabs with a single one:
tr -s '\t' '\t' < inputfile > outfile
The -s
option squeezes repeats:
-s, --squeeze-repeats
replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that 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