how to grep the oldest file under ls command

Hi, Please help me out

I want to grep the oldest file in a directory,
could I use "ls" command?
and how?

thanx in advance

grep -i pattern `ls -lt | awk '{}END{ print $NF }'`

HI, thanx for replying,
when I use

ls -lt | awk '{}END{ print $NF },

it prompt ">",
seems like it is not a complete command,
do u have any idea why?

sorry, please ignore previous message,
here is the real problem

when I type

ls -lt | awk '{}END{ print $NF }'

it did not return anything, but I do have lots files under that directory
all I want is the oldest one, do u have any idea why I am not getting any result?

thanx

ls -tr | head -1

Jean-Pierre.

thank u very much, that worked perfectly

This should work definitely,

try running ls -lt,
the filename from the last line will be displayed.

The END block is executed after all lines have been read, so $NF is not available in the END block. Try this mod:

ls -lt | awk '{vw=$NF}END{print vw}'