简体   繁体   English

如何将目录中的最新文件传递给 awk 输入文件?

[英]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 “ls -rt | tail -n 1”是目录中最新文件的名称

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' output 选择分隔符和必填字段进行打印。

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

Example:例子:

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

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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