greppipestdinxargsprocess-substitution

Using Grep with Xargs and Process Substitution


I'm trying to pass the grep query through xargs while passing the file through process substitution.

command1 | xargs -I{} grep {} <(command2)

make dummy files

for f in {1..50}; do echo $f >> test50.txt; done

for f in {25..30}; do echo $f >> test5.txt; done

xargs and process substitution with grep

cat test5.txt | xargs -I{} grep {} <(cat test50.txt)

output is :

25

desired output is :

25
26
27
28
29
30

I think the issue lies with how grep is receiving the input file, it's stopping after one line, whereas I would like it to search the entire input file


Solution

  • With GNU Parallel it looks like this:

    cat test5.txt | parallel 'grep {} <(cat test50.txt)'