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
eg. here's the contents of files.txt
This Filename Contains Spaces.htmYou can use tr to convert newlines to nulls. For example,
This one too.txt
stupid fuckers.doc
cat files.txt | tr '\n' '\0' | xargs -0 echowill give each line in files.txt to echo as a separate argument, whether that line contains spaces or not.