Biostar Beta. Not for public use.
Extraction of every n-th and m-th columns
Entering edit mode
13 months ago
mbk0asis • 420
Korea, Republic Of

Hi. Everyone!

I have a dataset similar to below. It has multiple samples, and each sample has multiple values.

ID    Sample1                     Sample2                    Sample3
xx    val1 val2 va3 val4 val5     val1 val2 va3 val4 val5    val1 val2 va3 val4 val5

How can I extract multiple columns from each sample (i.e. val2 and val4 from each sample) assuming all the data are tab delimited?

Thank you!

bash command • 375 views
Entering edit mode
15 months ago
Seattle, WA USA
$ awk -v M=1234 -v N=4567 -v FS="\t" -v OFS="\t" '{ print $M, $N; }' in.txt > out.txt

Replace M and N with your column indices of interest.

You could also use cut -fM,N in.txt > out.txt, so long as M < N. Using awk gets around quirks in cut.


Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.1