sed 's|[\t][\t][\t]*||g' file.txt
That will remove any instance of two or more tabs but will not affect any instances of single tabs.
If you've confirmed that you have the desired output and you want to edit the file in place, you can add -i
'
sed -i 's|[\t][\t][\t]*||g' file.txt
I've tested this with a file that has instances of 1,2,3,4 and 5 tabs it removed instances of multiple tabs while leaving instances of single tabs alone. It effectively removes any instance of two tabs with 0 or more tabs coming afterwards.
To confirm, I added some more lines with instances of multiple tabs and single tabs to what you have in your question:
The file with cat -vet
(Don't worry about the $
, it just represents a line ending. If you use cat -vT
, it doesn't have the $
for the line ending:
M^I^I^I^I^IJaghoub$
askdjfkasdf^I^Iksajk^I^Ijklsajkd$
klasjdfj^I^I^Ikljkasjdf^Ijaljkdsf$
asdkfj^I^I^Iklkljasdf^I^Ilkjkasdf$
sadfjkl^Ikjljas^Ikkjk^Ilkjlkj$
The output:
MJaghoub$
askdjfkasdfksajkjklsajkd$
klasjdfjkljkasjdf^Ijaljkdsf$
asdkfjklkljasdfkjkasdf$
sadfjkl^Ikjljas^Ikkjk^Ilkjlkj$
As you can see, it only removed instances of multiple tabs. The single tabs are still there.