What is the most efficient way to convert tab separated data such as this:
a b c d cat
NULL NULL NULL NULL NULL
NULL NULL NULL d d
NULL NULL c NULL c
NULL NULL c d c; d
NULL b NULL NULL b
NULL b NULL d b; d
NULL b c NULL b; c
NULL b c d b; c; d
a NULL NULL NULL a
a NULL NULL d a; d
a NULL c NULL a; c
a NULL c d a; c; d
a b NULL NULL a; b
a b NULL d a; b; d
a b c NULL a; b; c
a b c d a; b; c; d
Something close to this:
a | b | c | d | cat
-----+------+------+------+-----------
NULL | NULL | NULL | NULL | NULL
NULL | NULL | NULL | d | d
NULL | NULL | c | NULL | c
NULL | NULL | c | d | c; d
NULL | b | NULL | NULL | b
NULL | b | NULL | d | b; d
NULL | b | c | NULL | b; c
NULL | b | c | d | b; c; d
a | NULL | NULL | NULL | a
a | NULL | NULL | d | a; d
a | NULL | c | NULL | a; c
a | NULL | c | d | a; c; d
a | b | NULL | NULL | a; b
a | b | NULL | d | a; b; d
a | b | c | NULL | a; b; c
a | b | c | d | a; b; c; d
Currently I use Notepad++ as follows:
- Convert tabs to spaces
- Align the data manually
- Use column mode to insert the pipes
The second step is the most tedious one and I would rather have at least this part automated.
Note: I use a browser when working and sometimes I have a text editor open alongside. The efficient solution is the one that requires least amount of effort. I can use:
- Notepad++
- Generic text editor with regexp find/replace support
- JavaScript typed inside browser console
- Online web service
- PHP on command line (
php -a
)
awk
script.{{(⊃⍵)⍪⍉⍪↑¨↓⍉↑1↓⍵}s¨'⎕T'⎕T¨(s←1↓¨⊢⊂⍨⊢=⊃)¯1⌽⍵}
seems nice enough to work on, eh?)