Question: This is a tab-delimited txt.

```
A    B    D
C
K    s

```

So there is nothing in (2,2), (2,3) (3,3) entry, NOT EVEN TAB.

The maximum length row is 1st row, and 1st row has 3 columns.

Can I simply add 2 tabs to 2nd row, 1 tab to 3rd row, so that this tab-delimited txt becomes a "square"?

**What I have tried**

1. Tried to use notepad++'s replace. 

Find what:(blank), Replace with: \t, Checked 'Match whole word only'.

It didn't work.

Find what:(blank), Replace with: \t, Regular expression

It didn't work.
2. Tried python

```
import fileinput
for line in fileinput.FileInput("input.txt",inplace=1):
    line = line.replace("",\t)
    print line,

```

It didn't work for this purpose.

Answer: 
In Python you can use [`itertools.izip_longest`](https://docs.python.org/2/library/itertools.html#itertools.izip_longest) for this:

```
>>> from itertools import izip_longest
>>> s = 'A\tB\tD\nC\nK\ts'
>>> data = izip_longest(*(x.split('\t') for x in s.splitlines()), fillvalue='\t')
>>> for line in zip(*data):
      print line
...     
('A', 'B', 'D')
('C', '\t', '\t')
('K', 's', '\t')

```

If you're reading the data from a file:

```
with open('input.txt') as f:
    data = izip_longest(*(line.split('\t') for line in f), fillvalue='\t')
    print '\n'.join(map(''.join, zip(*data))

```
If you are using a method to normalise the file content so that it will become a tab-separated value (tsv) file, than you can do something like this:

```
def normalise(lines, max_num_of_columns=None):
    if max_num_of_columns == None:
       max_num_of_columns = max({len(line.split('\t')) for line in lines})
    for line in lines:
        content = line.split('\t')
        while len(content) < max_num_of_columns:
            content.append('')
        print '\t'.join(content)

lines = ['A\tB\tD\nC','K\ts']

normalise(lines)
...
A   B   D
C
K   s   

```

If you don't know the max\_num\_of\_columns you have to check the file first (see the first if).