0
$ cat logfile
1;1472223253;frank;12344;1472224386
2;1472223265;andrew;shop;
3;1472225515;frank;12345;1472225531
4;1472225526;joe;12344;1472225534

What can I run to get lines that contain numbers between 1472225000 and 1472226000?

3;1472225515;frank;12345;1472225531
4;1472225526;joe;12344;1472225534
2
  • Does field 5 (if present) qualify as a number to search for? (I assumed field 2). – Jeff Schaller Aug 26 '16 at 18:01
  • I'll get done what I need to just with field 2. Thanks! – aswine Aug 26 '16 at 18:17
4
awk -F';' '$2 > 1472225000 && $2 < 1472226000' < logfile

Tell awk to use semicolons as the field separator (-F';' -- the single quotes are to prevent the shell from seeing the semicolon as a command separator; you could use -F\;), then select lines where field 2 has values between those you provided. The default action for a line, once selected, is to print it.

Edit to generalize the solution to any field qualifying for comparison:

awk -F';' '{ 
  flag=0; 
  for (i=1;i<=NF;i++) if ($i > 1472225000 && $i < 1472226000) flag=1; 
  if (flag) print
}' < logfile

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.