How to extract only values greater than a threshold from a file?

Haikel Fazzani

I have this file:

names average
john:15.02
Mark:09.63
James:12.58

I want to extract only the averages greater than 10 from it, so the output in this example should be:

15.02
12.58
dessert

With awk

awk -F: '{if($2>10)print$2}' <filename

Explanations

  • -F: – sets the Field separator to :
  • {if($2>10)print$2} – for each line, test whether the 2nd field is >10, if so print it
  • <filename – let the shell open file filename, that's better than letting awk do that, see Stéphane Chazelas' answer on the topic

Example run

$ <filename awk -F: '{if($2>10)print$2}'
15.02
12.58

It's also possible to add spaces and put the pattern outside the brackets, so these are equal – thanks to Stefan for pointing that out:

awk -F: '{if($2>10)print$2}' <filename
awk -F: '{ if ( $2 > 10 ) print $2 }' <filename
awk -F: '$2>10{print$2}' <filename
awk -F: '$2 > 10 { print $2 }' <filename

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to extract only certain elements from JSON file and append to csv?

From Dev

MATLAB: how to find indices of cells which have length greater than threshold?

From Dev

Filter out values less than a threshold from a CSV file

From Dev

How to write the "greater than symbol" in a HTML file using a batch file

From Dev

How to extract attribute values from xml file with Stax?

From Dev

Count values which are different from NA and discard column if result is greater than threshold

From Dev

How to parse an XML file to get tag values and handle greater than and double quote characters?

From Dev

MySQL select records with sum greater than threshold

From Dev

How do I group hourly data by day and count only values greater than a set amount in Pandas?

From Dev

R Extract rows with values greater than previous columns

From Dev

Removing Columns from a Matrix in R when Any Value Is Greater, Equal or Less Than Threshold

From Dev

How to extract letter words only from an arbitrary input file

From Dev

How to filter array values greater than x

From Dev

setting values below a threshold to the threshold in a netcdf file

From Dev

Python: how to extract only values from dict?

From Dev

numpy.argmin for elements greater than a threshold

From Dev

How to easily break up a text file into pieces smaller than a threshold?

From Dev

MATLAB: how to find indices of cells which have length greater than threshold?

From Dev

How to extract only values greater than a threshold from a file?

From Dev

How to extract only one kind of file from the archive?

From Dev

How to extract data from a file and construct a filename from one of the values

From Dev

How to compare values greater than less than 0

From Dev

R Extract rows with values greater than previous columns

From Dev

Extract lines in a log file that are greater than a value

From Dev

Plot only values greater than given value: ggplot R

From Dev

How to parse a line which has a number after a certain string greater than a threshold?

From Dev

Extract values from a file and average

From Dev

How to extract specific values from a file and print them into another file

From Dev

how to select values of vector 2 only when the values of vector 1 is greater than 0

Related Related

  1. 1

    How to extract only certain elements from JSON file and append to csv?

  2. 2

    MATLAB: how to find indices of cells which have length greater than threshold?

  3. 3

    Filter out values less than a threshold from a CSV file

  4. 4

    How to write the "greater than symbol" in a HTML file using a batch file

  5. 5

    How to extract attribute values from xml file with Stax?

  6. 6

    Count values which are different from NA and discard column if result is greater than threshold

  7. 7

    How to parse an XML file to get tag values and handle greater than and double quote characters?

  8. 8

    MySQL select records with sum greater than threshold

  9. 9

    How do I group hourly data by day and count only values greater than a set amount in Pandas?

  10. 10

    R Extract rows with values greater than previous columns

  11. 11

    Removing Columns from a Matrix in R when Any Value Is Greater, Equal or Less Than Threshold

  12. 12

    How to extract letter words only from an arbitrary input file

  13. 13

    How to filter array values greater than x

  14. 14

    setting values below a threshold to the threshold in a netcdf file

  15. 15

    Python: how to extract only values from dict?

  16. 16

    numpy.argmin for elements greater than a threshold

  17. 17

    How to easily break up a text file into pieces smaller than a threshold?

  18. 18

    MATLAB: how to find indices of cells which have length greater than threshold?

  19. 19

    How to extract only values greater than a threshold from a file?

  20. 20

    How to extract only one kind of file from the archive?

  21. 21

    How to extract data from a file and construct a filename from one of the values

  22. 22

    How to compare values greater than less than 0

  23. 23

    R Extract rows with values greater than previous columns

  24. 24

    Extract lines in a log file that are greater than a value

  25. 25

    Plot only values greater than given value: ggplot R

  26. 26

    How to parse a line which has a number after a certain string greater than a threshold?

  27. 27

    Extract values from a file and average

  28. 28

    How to extract specific values from a file and print them into another file

  29. 29

    how to select values of vector 2 only when the values of vector 1 is greater than 0

HotTag

Archive