I have a csv file containing something like this:


Now I want to delte every line that contains a 23 in the third column.

Since there is a possibility that there is a 23 in the first one. It should only check for matches in the third column.

I would prefer the awk soloution, since I really want to learn it, but if someone can tell me how to do that with sed, I would be impressed!

It should work similar to this bad example of me.

awk -F ";" (if $3="23") delete Line
  • Would you like the output all columns except the last one?
    – user88036
    Sep 20, 2018 at 16:01
  • There are loads of learning resources about awk right here: all the StackExchange sites are part wiki. Click the awk tag, then click the Learn more… link on the awk tag page. Sep 20, 2018 at 17:17

3 Answers 3


Another variant is "if $3 is different from 23, print it"

awk -F';' '$3 != 23' file

A slight modification of your approach might already work (untested):

awk -F ";" '$3 ~ /23/ {next} 1' file

"contains" means "has, amongst others". If you mean "equals", use the == operator.

  • This would also delete line containing 230 etc. in the third column. Better to use $3 == 23. (oh, didn't see that last line... but anyway)
    – Kusalananda
    Sep 20, 2018 at 15:48
  • @Kusalananda: Thanks, but that was a bit diffuse in the request...
    – RudiC
    Sep 20, 2018 at 15:53
  • It is. 230 "contains 23"...
    – Kusalananda
    Sep 20, 2018 at 15:56

With sed

sed '/;23$/d' infile

If you can have more than 3 columns

sed '/\([^;]*;\)\{2\}23\(;\|$\)/d' infile

Or with ERE

sed -E '/([^;]*;){2}23(;|$)/d' infile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.