Extraction of every n-th and m-th columns
1
0
Entering edit mode
6.5 years ago
mbk0asis ▴ 680

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 • 1.0k views
ADD COMMENT
0
Entering edit mode
6.5 years ago
$ 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.

ADD COMMENT

Login before adding your answer.

Traffic: 2442 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6