to get last column of last row

Hello All,

My requirement is to go into /snlog directory and do ls -ltr to check the latest updated file and then move the name of the file in some variable.

My below code is code is doing the same, ls -ltr puts the output in file name tempo and then i use tail -1 tempo | awk '{print $9}' to get the last column of the last row, but problem is this that file tempo becomes the latest one and i need the name of file above it.

#
cd /snlog
ls -ltr > tempo
tail -1 tempo | awk '{print $9}'
rm -f tempo

for example:
# ls -ltr
-rw-r--r-- 1 ainet ainet 1716182 Sep 28 20:37 debuglog12
-rw-rw-rw- 1 ainet ainet 231975 Sep 28 20:39 PRMlog0
-rw-r--r-- 1 ainet ainet 3055155 Sep 28 20:40 mtclog1
-rw-r--r-- 1 ainet ainet 90274 Sep 28 20:40 scclog1
-rw-r--r-- 1 ainet ainet 173401 Sep 28 20:40 craftlog0
-rw-r--r-- 1 ainet ainet 6695666 Sep 28 20:40 OMlog0

i want the word OMlog0 in my variable.

but when i run my script so it gives output like this:

TCeCS01-1:/-# ./new
OMlog0
tempo

your_variable=`ls -ltr /snlog | tail -n 1 | awk '{print $9}'`

Thanks Alot.

Regards,
Waqas Ahmed

Try this :

$ ls -lrt | awk '{ f=$NF }; END{ print f }'

//Jadu

your_variable=`ls -ltr /snlog | awk 'END{print $NF}'`