Cat Example.txt # example file
1 2 3 4 5 6
7 8 9 10
11 12
Cat Example.txt | Xargs
1 2 3 4 5 6 7 8 9 10 11 12
-N num: One line gets more rows, num is the number of rows per row
Cat Example.txt | Xargs-n 3
1 2 3
4 5 6
7 8 9
10 11 12
-D: Split using custom qualifier (delimiter)
echo "Splitxsplitxsplitxsplit" | Xargs-d X
Split Split split split
Pass Parameters: INPUT | Xargs–n x, X is the number of arguments
Args.txt file:
Arg1
Arg2
Arg3
cecho.sh file:
#!/bin/bash
#Filename: cecho.sh
echo $* ' # '
Cat Args.txt | Xargs-n 1./cecho.sh #cecho. SH will be called 3 times
Output Result:
Arg1 #
ARG2 #
ARG3 #
Problem when working with find: find. -type f-name "*.txt"-print | Xargs rm-f #xargs默认分隔符是 "", if the file name is file Name.txt, Xargs a split error, causing the error file to be deleted
You must use the FIND-PRINT0 parameter to make the delimiter a, and use the-0 parameter in Xargs to specify the delimiter as "find." -type f-name "*.txt"-print0 | xargs-0 rm-f
To call the variable method separately:
Cat Files.txt | (while read Arg; does cat $arg; done)
Shell Xargs (GO)