1

I have to construct a csv with the output of a shell command; the csv file must contain for each row some information get by the output of stat command and in the last column the md5sum (only the sum without the filename)

I tried some command like:

find . -exec stat --printf='"%a";"%F"' {} \; -exec sh -c "md5sum $1 | cut -b-32" {} {} \;

but this block and ask me for input

and this,

find . -exec stat --printf='"%a";"%F";' {} \; -exec md5sum {} | cut -b-32 \;

but in this case the pipe doesn't work.

How can I solve it?

Elia C.
  • 11
  • 1
  • 3

1 Answers1

3

I think you have {} and ; misplaced. This one is working fine for me on Linux:

find . -exec stat --printf='"%a";"%F";' {} \; -exec sh -c "md5sum {} | cut -b-32" \;

Update 1

You can combine all in one -exec option like this also:

find . -exec sh -c "stat --printf='\"%a\";\"%F\";' {} && md5sum {} | cut -b-32" \;
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • the output is wrong: I have to do the cut only on the md5sum, your code do the cut on all the output – Elia C. May 10 '11 at 16:38
  • Actually it was your own command, I just fixed the syntax :) But good to know the actual intent, I will rework my answer. – anubhava May 10 '11 at 16:41