Linux shell: Using xargs with put argument to specified place

Give output data with pipe

cat samplefile
Tom
Mike
John

There is a file named samplefile

Give data to grep

cat samplefile | grep John
John

Output data be filtered with John using grep

In case of specify a file as 2nd argument

grep John samplefile
John

xargs

Backgrounds:
Monitored and detectioned log by ZABBIX will do edit using awk and cut.
and then I would like to the output will filter from any file using grep.

echo John | xargs echo
John

Output John with echo and then output will gave to xargs with pipe.
xargs put argument to right side of echo.

If give file as argument to grep and then give data from pipe it will occur an error

echo John | xargs grep samplefile
grep: John: no data and directly.

This example is supposed to xargs will put argument between grep and samplefile.

Using xargs with option -i for put argument to specified place

echo John | xargs -i grep {} samplefile
John

Using xargs with option -i , put { } to place that would like to put with output of left side of pipe .

same like this.
$ echo John | xargs -i grep John samplefile

Using read

echo John | (read v ; grep $v samplefile)
John
TwitterFacebookLinkedInHatenaPocketCopy Link