roger34
roger34

Reputation: 275

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}' 

Now 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.

Upvotes: 2

Views: 8617

Answers (4)

bmk
bmk

Reputation: 14147

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.

Upvotes: 0

William Pursell
William Pursell

Reputation: 212404


#!/bin/bash

ls -l $1 | awk '$3!=$4{ system( "ls -l '$1'/" $9}' 

Upvotes: 0

cdarke
cdarke

Reputation: 44394

Use awk system command:

ls -l $1 |awk '$3!=$4{system("ls -l " $9)}'

Upvotes: 2

mouviciel
mouviciel

Reputation: 67859

The command to use is xargs.

man xargs

should give some clues.

Upvotes: 1

Related Questions