print line only if number in third field is greater than X
Solution 1
You can do it with awk
itself for pattern matching instead of using grep
.
lsblk -bio KNAME,TYPE,SIZE,MODEL| awk '/disk/ && $3> 300000000000 || NR==1'
Or use scientific value 3e11
.
Solution 2
Short Awk approach:
lsblk -nbio KNAME,TYPE,SIZE,MODEL | awk '$3>3e11'
-n
(--noheadings
) - don't print headings$3
- the 3rd field (SIZE
column)3e11
- E-notation. the letterE
(ore
) is often used to represent "times ten raised to the power of" (which would be written as"× 10n
") and is followed by the value of the exponent; in other words, for any two real numbersm
andn
, the usage of "mEn
" would indicate a value ofm × 10n
.3e11
is equivalent to300000000000
.
Solution 3
Perl solution:
lsblk -bio KNAME,TYPE,SIZE,MODEL | perl -ane 'print if $F[2] > 3e11'
You can use 300_000_000_000 as the value also.
-n
reads the input line by line without printing-a
splits the input on whitespace into the @F array
Related videos on Youtube
yael
Updated on September 18, 2022Comments
-
yael over 1 year
The following
lsblk
command print the disk usage in byteslsblk -bio KNAME,TYPE,SIZE,MODEL| grep disk sda disk 298999349248 AVAGO sdb disk 1998998994944 AVAGO sdc disk 1998998994944 AVAGO sdd disk 1998998994944 AVAGO sde disk 98998994944 AVAGO
how to print the disks when disk is greater than 300000000000 , by adding after the pipe
awk
orperl
one-liner or elseexpected output:
lsblk -bio KNAME,TYPE,SIZE,MODEL| grep disk | ...... sdb disk 1998998994944 AVAGO sdc disk 1998998994944 AVAGO sdd disk 1998998994944 AVAGO
-
Marek Zakrzewski over 6 years
awk '$3 >= 1998998994944' infile
Sice your output doesn't have a disk larger than300000000000
you won't be able to print anything. The syntax will work in general.$3 > some_value
then print. -
yael over 6 yearsI not want to work with files
-