Extraction of rows which have a value > 50

2020-03-08 06:14发布

How to select those lines which have a value < 10 value from a large matrix of 21 columns and 150 rows.eg.

miRNameIDs  degradome   AGO     LKM......till 21
osa-miR159a      0       42      42
osa-miR396e      0        7       9
vun-miR156a     121      77       4
ppt-miR156a     12        7       4
gma-miR6300     118       2       0
bna-miR156a      0        114     48
gma-miR156k      0        46       1
osa-miR1882e     0        7        0
.
.
.

Desired output is:-

miRNameIDs  degradome   AGO    LKM......till 21
vun-miR156a      121    77      4
gma-miR6300      118    2       0
bna-miR156a       0    114      48
.
.
.
till 150 rows

标签: perl shell
1条回答
三岁会撩人
2楼-- · 2020-03-08 07:00

Using a perl one-liner

perl -ane 'print if $. == 1 || grep {$_ > 50} @F[1..$#F]' file.txt

Explanation:

Switches:

  • -a: Splits the line on space and loads them in an array @F
  • -n: Creates a while(<>){...} loop for each “line” in your input file.
  • -e: Tells perl to execute the code on command line.

Code:

  • $. == 1: Checks if the current line is line number 1.
  • grep {$_ > 50} @F[1..$#F]: Looks at each entries from the array to see if it is greater than 50.
  • ||: Logical OR operator. If any of our above stated condition is true, it prints the line.
查看更多
登录 后发表回答