Select lines based on value in a column

Tom

I have a tab delimited table for which I want to print all lines where column 'x' is greater than 'Y'. I have attempted using the code below but am new to using awk so am unsure how to use it based on columns.

awk '$X >= Y {print} ' Table.txt | cat > Wanted_lines 

Y are values from 1 to 100.

If the input were like below with column X were the second column.

1    30
2    50
3    100
4    100
5    80
6    79
7    90

The wanted output would be:

3    100
4    100
5    80
7    90

The first 2 lines of the file is:

1   OTU1    243622  208679  121420  265864  0   0   2   0   0   11  1   5   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   839604  OTU1    -   Archaea 100%    Euryarchaeota   100%    Methanobacteria 100%    Methanobacteriales  100%    Methanobacteriaceae 100%    Methanobrevibacter  100%
2   OTU2    84366   120817  15834   74737   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   295755  OTU2    -   Archaea 100%    Euryarchaeota   100%    Methanobacteria 100%    Methanobacteriales  100%    Methanobacteriaceae 100%    Methanobrevibacter  100%
Anthony Rutledge

First

awk's default internal field separator (FS) will work on space or tab delimited files.

Secondly

awk '$x > FLOOR' Table.txt

Where $x is the target column, and FLOOR is the actual numeric floor (i.e. 5000, etc ...)

Example file: awktest

500  100
400  1100
1000 400
1200 500


awk '$1 > 1000' awktest

1200   500

awk '$1 >= 1000' awktest

1000   400 
1200   500

Thus, you should be able to use a relational expression to print the lines where x > y, in the form:

awk '$x > $y' awktest

Where $x is a numeric column as in $1, or other.

Where $y is a numeric column as in $2, or other.

Example:

awk '$1 > $2' awktest

or ...

awk '$2 > $1' awktest

awk numbers are floating point numbers, so you can compare decimals, too.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select lines based on value in a column

From Dev

Conditional select based on column value

From Dev

Select multiple lines based on field value

From Dev

SELECT with temporary column with value based on other column

From Dev

SELECT with temporary column with value based on other column

From Dev

If duplicates exist, select the value based on another column

From Dev

Select new column based on existing value

From Dev

MySQL, select column name based on a value

From Dev

Select all the rows based on a column value pandas

From Dev

mysql select query php based on column value

From Dev

Sql select query based on a column value

From Dev

Select rows based on value in specific column

From Dev

Oracle Select Query based on Column value

From Dev

Select a checkbox based on a column value using XPath

From Dev

Select all the rows based on a column value pandas

From Dev

MySQL first select column based on parameter value and then value of column

From Dev

MySQL first select column based on parameter value and then value of column

From Dev

scala how to drop lines from df based on the column value

From Dev

Select lines based on length

From Dev

extract lines based on a column

From Dev

How to transform SELECT output column to arbitrary value based on this column?

From Dev

SELECT Mysql - Replacing value in one column based on another column

From Dev

How to select boolean column based on the other column value in SQL?

From Dev

How to transform SELECT output column to arbitrary value based on this column?

From Dev

SQL Server - Select column to update based on another column value

From Dev

select mysql column based on occurrence and value in another column

From Dev

SQL query add custom value to select based on distinct column value

From Java

'IF' in 'SELECT' statement - choose output value based on column values

From Dev

MySQL: Putting condition in SELECT query based on column value

Related Related

  1. 1

    Select lines based on value in a column

  2. 2

    Conditional select based on column value

  3. 3

    Select multiple lines based on field value

  4. 4

    SELECT with temporary column with value based on other column

  5. 5

    SELECT with temporary column with value based on other column

  6. 6

    If duplicates exist, select the value based on another column

  7. 7

    Select new column based on existing value

  8. 8

    MySQL, select column name based on a value

  9. 9

    Select all the rows based on a column value pandas

  10. 10

    mysql select query php based on column value

  11. 11

    Sql select query based on a column value

  12. 12

    Select rows based on value in specific column

  13. 13

    Oracle Select Query based on Column value

  14. 14

    Select a checkbox based on a column value using XPath

  15. 15

    Select all the rows based on a column value pandas

  16. 16

    MySQL first select column based on parameter value and then value of column

  17. 17

    MySQL first select column based on parameter value and then value of column

  18. 18

    scala how to drop lines from df based on the column value

  19. 19

    Select lines based on length

  20. 20

    extract lines based on a column

  21. 21

    How to transform SELECT output column to arbitrary value based on this column?

  22. 22

    SELECT Mysql - Replacing value in one column based on another column

  23. 23

    How to select boolean column based on the other column value in SQL?

  24. 24

    How to transform SELECT output column to arbitrary value based on this column?

  25. 25

    SQL Server - Select column to update based on another column value

  26. 26

    select mysql column based on occurrence and value in another column

  27. 27

    SQL query add custom value to select based on distinct column value

  28. 28

    'IF' in 'SELECT' statement - choose output value based on column values

  29. 29

    MySQL: Putting condition in SELECT query based on column value

HotTag

Archive