xargs: String concatenation

User picture User · Jun 20, 2012 · Viewed 17k times · Source
zgrep -i XXX XXX | grep -o "RID=[0-9|A-Z]*" |
   uniq | cut -d "=" -f2 |
   xargs -0 -I string echo "RequestID="string

My output is

RequestID=121212112
8127127128
8129129812

But my requirement is to have the request ID prefixed before all the output. Any help is appreciated

Answer

Lev Levitsky picture Lev Levitsky · Jun 20, 2012

Try -n option of xargs.

-n max-args

Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will exit.

Example:

$ echo -e '1\n2' | xargs echo 'str ='
str = 1 2

$ echo -e '1\n2' | xargs -n 1 echo 'str ='
str = 1
str = 2