How to concatenate stdin and a string?

前端 未结 9 1474
死守一世寂寞
死守一世寂寞 2021-01-30 01:49

How to I concatenate stdin to a string, like this?

echo \"input\" | COMMAND \"string\"

and get

inputstring
9条回答
  •  终归单人心
    2021-01-30 02:23

    I know this is a few years late, but you can accomplish this with the xargs -J option:

    echo "input" | xargs -J "%" echo "%" "string"
    

    And since it is xargs, you can do this on multiple lines of a file at once. If the file 'names' has three lines, like:

    Adam
    Bob
    Charlie
    

    You could do:

    cat names | xargs -n 1 -J "%" echo "I like" "%" "because he is nice"
    

提交回复
热议问题