1

I have a tab-delimited file and want to add a new column based on the values in an existing column. My file looks like this:

CHR  SNP  A1  A2  MAF    NCHROBS
1    rs   G   A   0.001  1432
1    rs   A   C   0.2    1432

I want to categorize the MAF column into two groups in the new column: values that are less than 0.01 are assigned "1" in the new column and those that are greater than 0.01 are assigned "2".

Thank you.

4

1 回答 1

1

try this awk one-liner: (I just named the new column title as "NEW")

 awk -v OFS="\t" 'NR==1{print $0,"NEW";next}{print $0,($5>=0.01?2:1)}' file

the output with your example is:

CHR     SNP     A1      A2      MAF     NCHROBS NEW
1       rs      G       A       0.001   1432    1
1       rs      A       C       0.2     1432    2
于 2013-05-02T14:14:03.253 回答