Extraction of rows which have a value > 50

2020-03-08 06:24发布

问题:

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

回答1:

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.


标签: perl shell