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))

```
Pretty ugly and inefficient, but I found this gets the job done:

```
myStr = "A\tB\tD\nC\nK\ts"

maxLen = max([len(line.split('\t')) for line in myStr.split('\n')])

newstr = ''.join([line + ('\t' * (maxLen - len(line.split('\t')))) + '\n' for line in myStr.split('\n')])

>>> newstr
'A\tB\tD\nC\t\t\nK\ts\t\n'

```

might have to be modified a bit depending on how your input looks, how you're handling newlines, etc. But I think that's the basic idea. You find the max length of a line and go through and make all your other lines that length by filling up with tabs.