I have a tsv file that has the header separated by tabs but each row is separated by one or more tabs. The parser/viewer I'd like to use doesn't understand that the values are separated by a series of tabs. It expects there to be just one tab between values.

How can I use Vim or another program to find and replace all series of tabs (of variable length) with just one tab?

1 Answer 1


welcome to stackexchange! :)

You can do this by selecting the line(s) you are interesting in and using the following substitution command: s/\t\+/\t/g

The structure of this command is the following: s/pattern/substitution/g

  • pattern is \t\+, which means one tab or more
  • substitution is \t, which means one tab
  • ending with /g means that you will do this substitution multiple times one a single line, as many times as there are matches on your pattern

Hope this helps!

  • 1
    "pattern is \t\+, which means one tab or more" - this was what I was missing. Good to know. Thank you! I actually realized that the tsv file just has a lot of NA/null values and I didn't actually need to do this. Still though, this will help me in the future. I really appreciate it! Commented Nov 27, 2022 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.