I have a huge file like below. I want to delete the rows if second column is having values 60,30 etc., all these values I will get from another file in comma separated file.
position_id risk_measure_id Scenario_id value_usd
1 60 0 300.8
2 30 0 400.6
3 45 90 300.7
4 60 0 200.9
5 30 9 400.8
6 60 10 4000.9
8 20 0 5000.9
I can use below awk
command to achieve it but if I have multiple values to exclude is there any easy way.
$ awk '{ if ($2!=60 && $2!=25 && $2!=30) print $0}' test.txt
position_id risk_measure_id Scenario_id value_usd
3 45 90 300.7
8 20 0 5000.9
Best Answer
Put your values in another file:
values
:Then read them into an array in
awk
:FNR == NR
holds true when reading the first file, so the first block is only executed while reading the values. Because of thenext
, the!($2 in arr)
is only executed for the second file.