Skip to main content
Post Closed as "Duplicate" by AdminBee, terdon awk
edited tags
Link
terdon
  • 252.2k
  • 69
  • 480
  • 718
Source Link

select rows based on specific column values

How can I select all rows in a text file based on different values of a particular column? The desired values are not in a specific interval.

A short example of what I expect is given below.

My data stored in a text file input.txt

1.0     21
2.5     23
4.0     21
6.5     45
9.0     30
16.5    46
2.0     78
1.0     20
1.6     19
2.5     25
4.0     40
5.2     16
6.5     25
9.0     47
10.0    14
16.5    60
18.5    65
20.0    57
.
.etc

I want to select rows based on 1st column having values 2.5,6.5,16.5,..., etc

So the output will look like this. I don't want to sort output numerically by 1st column.

2.5     23
6.5     45
16.5    46
2.5     25
6.5     25
16.5    60

I am looking for solutions in awk or sed or paste

Thanks in advance.