Hi I am using the following to get the filename
ls -lrt filename* | tail -1 | awk {'print$9'}
o/p : filename-20101117
want to extract 20101117 from the filename ..
Pls advise
Hi I am using the following to get the filename
ls -lrt filename* | tail -1 | awk {'print$9'}
o/p : filename-20101117
want to extract 20101117 from the filename ..
Pls advise
ls -lrt filename* | tail -1 | awk {'print$9'} | cut -d'-' -f2
ls -lrdt filename* | sed -n '$s/.*-//p'
or rather:
ls -ldt filename* | sed 's/.*-//;q'
the same if you want to use awk only
ls -lt filename* | awk -F- 'NR==1{print $NF}'
ls -lrdt filename* | awk -F- '{p=$NF}END{print p}'
---------- Post updated at 10:43 ---------- Previous update was at 10:42 ----------
Morning
ls -lrt filename* | awk -F- 'NR==1{print $NF}'
the o/p comes at 20101116.txt
ls -lrt filename* | awk -F- 'NR==1{print $NF}' | cut -d'.' -f2
o/p txt
I require only 20101116 as o/p
ls -lt filename* | awk -F"[-.]" 'NR==1{print $(NF-1)}'
thru sed..
ls -lt filename*| sed -n '1s/.*-\([0-9]\+\)\..../\1/p'