【发布时间】:2019-06-18 09:49:43
【问题描述】:
我的文件看起来像:
This is a RESTRICTED site.
All connections are monitored and recorded.
Disconnect IMMEDIATELY if you are not an authorized user!
sftp> cd outbox
sftp> ls -ltr
-rw------- 1 0 0 1911 Jun 12 20:40 61N0584832_EDIP000749728818_MFC_20190612203409.txt
-rw------- 1 0 0 1878 Jun 13 06:01 613577165_EDIP000750181517_MFC_20190613055207.txt
我只想打印 .txt 文件名,最好是在一个命令中。
我能做到:
grep -e '^-' outfile.log > outfile.log2
..它只给出以'-'开头的行。
-rw------- 1 0 0 1911 Jun 12 20:40 61N0584832_EDIP000749728818_MFC_20190612203409.txt
-rw------- 1 0 0 1878 Jun 13 06:01 613577165_EDIP000750181517_MFC_20190613055207.txt
然后:
awk '{print $9}' outfile.log2 > outfile.log3
..它给出了所需的输出:
61N0584832_EDIP000749728818_MFC_20190612203409.txt
613577165_EDIP000750181517_MFC_20190613055207.txt
那么问题来了,这2个命令可以合并成1个吗?
【问题讨论】:
-
dos2unix < outfile.log | grep -Po '[^ ]*txt$' -
您的文件名曾经是否可以包含空格,例如。
61N0584832 MFC_20190612203409.txt?