I intend to modify the output of ls -la to display the output of file command. The below command works well for the purpose

find /opt -type f | xargs ls -let | awk 'BEGIN { OFS="\t" } { sprintf("file \"%s\"", $10) | getline type; print type,$1,$3,$4 }' | tr ":" "\t"

Now, I want to modify this to display the ouput of ldd command(comma separated), if the file type output matches pattern "ELF.*execuatble". I tried various combinations to match a keyword using if inside that awk, and if the match is successful, to run ldd, but to no avail.

Is this possible?

The operating system is Solaris and I am working in ksh.

  • 1
    I failed to run your awk code on solaris. what do you intend with sprintf("file \"%s\"", $10) | getline type ? shouldn't you use printf "file \%s\" %s %s %s\n",$10,$1,$3,$4 ; ? have you consider changing your find clause to find bin -type f -ls -exec file {} \; ? – Archemar May 11 '15 at 7:36
  • @Archemar I intended to print the output of file command on the files. Your version works too with minor modifications I am sure. I did not consider the command you just gave - guess i should have. It prints out the exact same thing but in two lines which I will try to work around. Seems like I was unnecessarily complicating my life with the basic requirement. Thanks much! To run on solaris, use /usr/xpg4/bin/ binaries in PATH - am able to run my command using that. – Prasoon May 11 '15 at 7:54

awk provides pattern matching

awk '/ELF*.executable/ { ... }'

EDIT: in your case:

find /opt -type f | xargs ls -let | awk 'BEGIN { OFS="\t" } /ELF*.executable/ { sprintf("file \"%s\"", $10) | getline type; print type,$1,$3,$4 }' | tr ":" "\t"
  • I already am using an awk and running a command within, and i was looking at pattern matching the output of that command. Don't think that is doable because awk within awk won't be an option. – Prasoon May 11 '15 at 10:29
  • Not inside, just add the pattern to your awk command. I added my answer. Btw: why you use ls -le, in my understanding -l and -e is the same, except the timestamp, so -e would be enough. – quenia May 11 '15 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.