简体   繁体   中英

how to pass the most recent file from a directory to awk input file?

It should be something like that:

    awk '

       ...

     ' ls -rt | tail -n 1

"ls -rt | tail -n 1" is the name of the most recent file from a directory

Thank you in advance

You can use format mentioned below, please choose separtor and required field to print as per your 'ls -lr' output.

 ls -lr <directoryName|*>| tail -n 1|awk -F<separator> '{ print $<tokenNumber> }'

Example:

ls -lr cpas| tail -n 1|awk -F: '{ print $2 }'

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM