xargs: String concatenation

19,056

Solution 1

I had a similar task and this worked for me. It might be what you are looking for:

zgrep -i XXX XXX | grep -o "RID=[0-9|A-Z]*" | uniq | cut -d "=" -f2 | xargs -I {} echo "RequestID="{}

Solution 2

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
Share:
19,056
User
Author by

User

Updated on July 27, 2022

Comments

  • User
    User almost 2 years
    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