Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Emulating 'find's print0...



On 2016-11-23 08:24, Meino.Cramer@xxxxxx wrote:
cat-ting a list of file like so

    cat files.txt | xargs md5sum | sort | .........

fails, if a files name contains blanks.

The tool find circumvent this by using print0
and xargs understands this via -0.

But I dont want to use find in this case, since the
list of files (files.txt) are hand made and a manual
selection of files.

Is there any way to emulate "-print0" efficiently
(that is: without accessing the drive again) ?

You could use the -I option of xargs:

$ cat files.txt
test 1
test2
test with more blanks
$ cat files.txt | xargs -I @ md5sum @ | sort
26ab0db90d72e28ad0ba1e22ee510510  test2
6d7fce9fee471194aa8b5b6e47267f03  test with more blanks
b026324c6904b2a9cb4b88d6d61c81d1  test 1

With "-I replstr", xargs always takes a full line and replaces every occurence of "replstr" in the argument list of the utility with that line.

The GNU version of xargs also has the -a option which eliminates the cating:

$ xargs -a files.txt -I @ md5sum @ | sort
26ab0db90d72e28ad0ba1e22ee510510  test2
6d7fce9fee471194aa8b5b6e47267f03  test with more blanks
b026324c6904b2a9cb4b88d6d61c81d1  test 1

Bye, Andreas



Messages sorted by: Reverse Date, Date, Thread, Author