Best output format for Xargs

I am writing a simple program to run through many files in different directories on my system. This mainly concerns their discovery and XML validation. One of the options for this program is a list of bad xml files.

This leads me to my question. What is the best result for formatting this for use with XARGS. I thought that each entry on a new line would be good enough, but it seems a bit confusing. because file names have spaces.

So my conclusion is:

./dir name 1/file 1.xml
./dir name 2/file 2.xml
./dir name 3/file 3.xml

I tried the following command, but it continues to say "There is no such file or directory."

./myprogram.py --list BADXML | xargs -d '\n' cat

So, I either misunderstand how to use XARGS, or I need to slightly change the output format of my program. I'm not sure the easiest to use) route to take here. I would not want to always mess up the xarg options if I can avoid it.

+3
source share
3 answers

man xargs

- null

-0 Input elements are terminated by a null character, not spaces, and quotes and backslashes are not special (each character is taken literally). Disables the end of a file line, which is treated like any other argument. Useful when input elements can contain space, quotation marks or backslashes. The GNU find -print0 option produces input suitable for this mode.

+2

xargs :

./myprogram.py --list BADXML | while read -a line; do cat "${line[*]}"; done

, xargs, ...

, xargs , , -), xargs, xargs ,

batch10cat () {
    local i=1 argv line
    declare -a argv
    while read -r line; do
        argv[i]="$line"
        let i++
        if test $i -gt 10; then i=1; cat "${argv[@]}"; fi
    done
    if test $i -gt 1; then cat "${argv[@]}"; fi
}
./myprogram.py --list BADXML | batch10 cat
+1

GNU Parallel http://www.gnu.org/software/parallel/ myprogram.py:

./myprogram.py --list BADXML | parallel cat

: .

0

Source: https://habr.com/ru/post/1730727/


All Articles