So I have a
TSV file that looks something like this:
Hello world how are you 1 2 3 4 5 6 7 8 9 0
(I've separated everything within each row with a single whitespace in the hand-written toy example above.)
My objective is to get the columns that contain "how" and "are" as the first row values. The output, therefore, would look like this:
how are 3 4 8 9
The problem is that I do not know which column these patterns (i.e., "how" and "are") will occur. So, for example, the
TSV file could actually be arranged like this:
Hello how world are you 1 3 2 4 5 6 8 7 9 0
I know how I can deal with this in, say, something like
python (just transpose the file, and then select the rows I want) but I'd like to do it in the shell (for reasons). The problem is, I don't know how to. I know that transposition is also possible using command line utilities (e.g., see here) but I'd like to avoid that bulky code if I can. My initial, simple-minded solution was to just
grep "how" and "are" but that obviously returned the entire file, and that's where I've been stuck since.
Any help or pointers would be appreciated!
Edit: I must mention, I do not have privileges to install any new tools on this machine. I am also quite uncertain what it actually comes with. If it helps, this is
Scientific Linux 7.3 (Nitrogen).