aksg24
aksg24

Reputation: 701

how to remove one tab out of two consequetive tabs in linux

i have a file in which all columns are tab separated. at some places two or more tabs are present consecutively. so i want to keep one tab out of two or more tabs. input file is as following-

10517-akr   0   0   0   0   0   0   0   0
10518-akr       0   0   0   1   0   0   0
10515-akr   0   0   0   0   4   0   0   0
10514-akr           0   1   17  0   0   0
10513-akr   0   0   0   0   1   0   0   0

Desired out put is-

10517-akr   0   0   0   0   0   0   0   0
10518-akr   0   0   0   1   0   0   0
10515-akr   0   0   0   0   4   0   0   0
10514-akr   0   1   17  0   0   0
10513-akr   0   0   0   0   1   0   0   0

Upvotes: 1

Views: 609

Answers (2)

umläute
umläute

Reputation: 31334

using sed to replace double-tab by single tab:

sed 's|\t\t|\t|g' inputfile > outputfile

or - if you want to replace any repetition of tabs:

sed 's|\t\t*|\t|g' inputfile > outputfile

note, that not all versions of sed understand \t. Just insert a literal tab instead (press Ctrl-V then Tab).

Upvotes: 1

devnull
devnull

Reputation: 123608

You can use tr to squeeze multiple repeated tabs into one:

tr -s '\t' < inputfile > outfile

Quoting man tr:

   -s, --squeeze-repeats
          replace each input sequence of  a  repeated  character  that  is
          listed in SET1 with a single occurrence of that character

Upvotes: 3

Related Questions