bash 如何对 awk 字段的输出执行 ls 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5874187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do an ls command on output from an awk field
提问by roger34
This takes a directory as a parameter:
这需要一个目录作为参数:
#!/bin/bash
ls -l |awk '!={print }'
Now what I need is to be able to do ANOTHER ls -lon the just the files that are found from the awk statement.
现在我需要的是能够ls -l仅对从 awk 语句中找到的文件执行 ANOTHER 。
Yeah, it sounds dumb, and I know of like 3 other ways to do this, but not with awk.
是的,这听起来很愚蠢,而且我知道其他 3 种方法可以做到这一点,但不能使用 awk。
采纳答案by William Pursell
#!/bin/bash
ls -l | awk '!={ system( "ls -l ''/" }'
回答by cdarke
Use awk system command:
使用 awk 系统命令:
ls -l |awk '!={system("ls -l " )}'
回答by mouviciel
The command to use is xargs.
要使用的命令是xargs.
man xargs
should give some clues.
应该给出一些线索。
回答by bmk
If it is allowed to adjust the first ls -lyou could try to do:
如果允许调整第一个,ls -l您可以尝试执行以下操作:
ls -ld ""/* |awk '!={print }' | xargs ls -l
In this case lswill prefix the directory. But I don't know if this is portable behavior.
在这种情况下,ls将为目录添加前缀。但我不知道这是否是可移植的行为。

