4

It tried to grep strings with number <4 in 3rd column. My data:

52343523412312;52343523412312;4 
52343523412312;52343523412312;4
52343523412312;52343523412312;4
52343523262412;52343523262412;3

I tried AWK:

awk -F; '$3!="4"'

But still receive an error - awk: option requires an argument -- F

What I'm doing wrong?

1
  • 3
    Always, always, always quote every string (e.g. the ; after -F) in shell unless you have a very specific reason not to. See mywiki.wooledge.org/Quotes. The best way to think of using quotes when starting out is that quotes aren't something you add when you think you need to, they're something you always use by default and only remove when you know you need to. – Ed Morton May 12 at 16:40
12

A few things. Your shell uses ; as the command separator, so you need to quote it (or escape it with \) for your command. Also, you shouldn't quote the 4 as it's a number. Lastly, you wanted "less than 4", not "not equal to 4". So, overall, you can do:

awk -F';' '$3<4'
0
0

Python

#!/usr/bin/python

k=open('filename','r')
for i in k:
    gh=i.split(';')
    if (int(gh[2]) < 4):
        print i.strip()

output

python scr.py 
52343523262412;52343523262412;3



awk ===> Alread best solution provided Below is just with if condition

 awk -F ";" '{if($3 < 4){print $0}}' filename
52343523262412;52343523262412;3

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.