Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a line with a specific pattern in one field

Below is my input file, input.txt:

Value Value1 value2
5 1 2
1 4 3
2 1 5.5
0 0 0
4 1 0

I need to search the value(5.5) in the 3rd column, if found i need to remove the row entirely.

And i need the output like below, output.txt:

Value Value1 value2
5 1 2
1 4 3
0 0 0
4 1 0

i have tried awk command to remove the row, but I'm stuck with the below part(???). Don't to how to remove the row entire row from awk command. please suggest way to achieve this. Thanks!
awk -F"\t" '{if($3==5.5) ??? }'

like image 755
Marjer Avatar asked Dec 20 '22 04:12

Marjer


2 Answers

If you want exclude all lines with 3rd column's value 5.5 then:

awk '$3!=5.5' filename
like image 148
P.P Avatar answered Dec 25 '22 22:12

P.P


GNU safer sed

sed -r '/\s*(\S+\s+){2}5.5/d' file
like image 45
captcha Avatar answered Dec 26 '22 00:12

captcha