How to take the result of awk as the pattern parameter of grep?

for example

grep 20180906834424 test.log | awk "{print $2}" 

the above code will produce a result. How can I use this result as a parameter of grep to re-search the test.log file?

grep 20180906834424 test.log | awk "{print $2}"  | xargs grep PATTERN test.log

result, the result of awk is always used as the file name. How can it be regarded as PATTERN?

May.27,2021

xargs-I {} will build the command line into an execution process similar to a for loop. Consider using splicing pattern to speed up the execution process, only grep once.

 

use the option-I of xargs to indicate which parameter bit of the subsequent command you want to populate the contents of the pipe to.

grep 20180906834424 test.log | awk'{print $2}'| xargs-I {} grep {} test.log

should be a

that can meet your needs.
Menu