How to do an ls command on output from an awk field
This takes a directory as a parameter:
#!/bin/bash
ls -l $1 |awk '$3!=$4{print $9}'
No开发者_开发知识库w what I need is to be able to do ANOTHER ls -l
on the just the files that are found from the awk statement.
Yeah, it sounds dumb, and I know of like 3 other ways to do this, but not with awk.
Use awk system command:
ls -l $1 |awk '$3!=$4{system("ls -l " $9)}'
The command to use is xargs
.
man xargs
should give some clues.
#!/bin/bash ls -l $1 | awk '$3!=$4{ system( "ls -l '$1'/" $9}'
If it is allowed to adjust the first ls -l
you could try to do:
ls -ld "$1"/* |awk '$3!=$4{print $9}' | xargs ls -l
In this case ls
will prefix the directory. But I don't know if this is portable behavior.
精彩评论