1

I tried doing something like this in awk?

limit=10000  
ls -ltr | awk '$5 >= $limit { print $5 }'

But it doesn't seem to work, it prints all size less than the limit too.
Thanks in advance!

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
Malick
  • 477
  • 4
  • 16
  • possible duplicate of [How to use shell variables in awk script](http://stackoverflow.com/questions/19075671/how-to-use-shell-variables-in-awk-script) – fedorqui Nov 19 '14 at 10:12

2 Answers2

0

Try to set variable in AWK's paramaters using -v option:

limit=10000
ls -ltr | awk -v mylimit=$limit '$5 >= mylimit {print $5}'
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
Troublemaker-DV
  • 174
  • 1
  • 11
0

Change your awk command like below,

ls -ltr | awk -v limit=10000 '$5 >= limit { print $5 }'

you could declare an variable in awk itself using -v switch.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274