I have a strange problem with xargs.
I have an xargs construct which does not work, even though
when I echo the command, it works perfectly.
My one liner is the following:
exiftool -p exifprintformat -if '$Subject =~/DATA/i' -q *.pdf |grep pdf |sed 's/ //g'|xargs|xargs -0 -I % pdftk % cat output binder1.pdf
and the output
Error: Unable to find file. Error: Failed to open PDF file: 20170105170516234.pdf 20170105173126944.pdf 20170105173209758.pdf 20170621163418079.pdf
- The
exiftool
selects all the pdf that contain the word DATA in the subject tag, - The
-p exifprintformat
instructsexiftool
to print only the file name, - The
grep
selects only the lines with pdf, - The
sed
removes whitespaces, - The first
xarg
makes all the lines into one string and the second constructs the bind command) when I run
exiftool -p exifprintformat -if '$Subject =~/DATA/i' -q *.pdf |grep pdf |sed 's/ //g'|xargs|xargs -I{} echo pdftk {} cat output binder1.pdf
I get
pdftk 20170105170516234.pdf 20170105173126944.pdf 20170105173209758.pdf 20170621163418079.pdf cat output binder1.pdf
which works perfectly.
Obviously, I am doing something wrong...But what?
grep
expects line endings (probably present) anddarfst -0
expects NUL bytes (probably missing)