.comment-link {margin-left:.6em;} <$BlogRSDURL$>

Friday, August 11, 2006

xargs: using xargs -0 with arbitrary input 

Sure, we all know how to use xargs -0 when the input is delimited by \0, but what if our input to xargs contains spaces and is delimited by returns?
eg. here's the contents of files.txt
This Filename Contains Spaces.htm
This one too.txt
stupid fuckers.doc
You can use tr to convert newlines to nulls. For example,
cat files.txt | tr '\n' '\0' | xargs -0 echo
will give each line in files.txt to echo as a separate argument, whether that line contains spaces or not.

Comments: Post a Comment


This page is powered by Blogger. Isn't yours?