xargs 将标准输入转换成命令行参数

1. 命令功能

xargs 命令过滤器,接收管道或者标准输入传递的数据转换成xargs命令。

2. 语法格式

xargs [option]

xargs  选项

参数

参数说明

-n

指定每行的最大参数量n,

-d

自定义分隔符

-i

已{}替代前面的结果

-I

指定一个符号替代前面的结果,而不用-i参数默认的{}

-p

提示让用户确认是否指定后面的命令,y执行,n不执行

-0(数字0)

用null代替空格作为分割符,配合find命令的-print选项输出

3. 使用范例

范例1: 多行输入编程单行的例子

[cxf@localhost test]$ cat test.txt

a b c d

e f g h

l i m n

o p q r

1 2 4 3

[cxf@localhost test]$ xargs < test.txt

a b c d e f g h l i m n o p q r 1 2 4 3

范例2 :通过-n 指定每行的输出个数为6

[cxf@localhost test]$ xargs -n 6 < test.txt 

a b c d e f

g h l i m n

o p q r 1 2

4 3

范例3: 自定义分隔符 –d

[cxf@localhost test]$ echo "abc@adfre2@sdfvcs@13334@dfgsd@" |xargs -d @

abc adfre2 sdfvcs 13334 dfgsd    #以@作为分割符

原文地址:https://www.cnblogs.com/joechu/p/8664355.html