Store grep output in an array [duplicate] Store grep output in an array [duplicate] shell shell

Store grep output in an array [duplicate]


You can use:

targets=($(grep -HRl "pattern" .))

Note use of (...) for array creation in BASH.

Also you can use grep -l to get only file names in grep's output (as shown in my command).