Shell Xargs (GO)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.