Search and delete

A file(example viv.txt) contains a n number of rows like

1,2,3,4,5,6,7,8
11,22,33,44,55,66,77,88
1,3,9,7,8,5,2,6,4

Requirement:
If number "5" exist in the sixth position then it should delete the whole line.like this it should check for all rows in a file(viv.txt)
.

please help on this.

awk -F, '$6 == 5 {next}1' viv.txt > output
1 Like

Or just

awk -F"," '$6 != 5'

A bare expression like that is an implied "if such-and-such, then print", like

{ if($6 != 5) { print } }
1 Like

above command is putting result in a file "output",i want to do changes in source file"viv.txt" itself.

A crude way of doing it...

sed -n '/[0-9]\{1,\},[0-9]\{1,\},[0-9]\{1,\},[0-9]\{1,\},[0-9]\{1,\},5,/!p' viv.txt|tee viv.txt >/dev/null

I'd recommend still using a temp file, and then moving it on top.

awk -F"," '$6 != 5' viv.txt > viv.tmp && mv viv.tmp viv.txt