* Emulating 'find's print0...
@ 2016-11-23 7:24 Meino.Cramer
2016-11-23 9:40 ` Andreas Perstinger
2016-11-23 16:39 ` Mikael Magnusson
0 siblings, 2 replies; 4+ messages in thread
From: Meino.Cramer @ 2016-11-23 7:24 UTC (permalink / raw)
To: zsh-users
Hi,
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) ?
Thank you very much in advance for any help!
Cheers
Meino
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Emulating 'find's print0...
2016-11-23 7:24 Emulating 'find's print0 Meino.Cramer
@ 2016-11-23 9:40 ` Andreas Perstinger
2016-11-23 16:39 ` Mikael Magnusson
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Perstinger @ 2016-11-23 9:40 UTC (permalink / raw)
To: zsh-users
On 2016-11-23 08:24, Meino.Cramer@gmx.de 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Emulating 'find's print0...
2016-11-23 7:24 Emulating 'find's print0 Meino.Cramer
2016-11-23 9:40 ` Andreas Perstinger
@ 2016-11-23 16:39 ` Mikael Magnusson
2016-11-23 17:25 ` Bart Schaefer
1 sibling, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2016-11-23 16:39 UTC (permalink / raw)
To: Meino.Cramer; +Cc: Zsh Users
On Wed, Nov 23, 2016 at 8:24 AM, <Meino.Cramer@gmx.de> wrote:
> Hi,
>
> 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) ?
If you use a reasonable version of xargs, you can specify -d\\n to
only split on newlines. (POSIX xargs doesn't have it, but then again,
POSIX xargs is almost impossible to use safely).
Some examples:
% print -l "one line" "another line" | xargs printf %s\\n
one
line
another
line
% print -l "one'line" "another line" | xargs printf %s\\n
xargs: unmatched single quote; by default quotes are special to xargs
unless you use the -0 option
% print -l "one'line" "another line" | xargs -d\\n printf %s\\n
one'line
another line
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Emulating 'find's print0...
2016-11-23 16:39 ` Mikael Magnusson
@ 2016-11-23 17:25 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-11-23 17:25 UTC (permalink / raw)
To: Zsh Users
On Wed, Nov 23, 2016 at 8:39 AM, Mikael Magnusson <mikachu@gmail.com> wrote:
> On Wed, Nov 23, 2016 at 8:24 AM, <Meino.Cramer@gmx.de> wrote:
>> Hi,
>>
>> cat-ting a list of file like so
>>
>> cat files.txt | xargs md5sum | sort | .........
>>
>> fails, if a files name contains blanks.
I'm surprised no one has yet mentioned zargs.
autoload -Uz zargs
zargs -- "${(@f)$(<files.txt)}" -- md5sum | ...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-23 17:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23 7:24 Emulating 'find's print0 Meino.Cramer
2016-11-23 9:40 ` Andreas Perstinger
2016-11-23 16:39 ` Mikael Magnusson
2016-11-23 17:25 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).