Saturday, April 9, 2022

[SOLVED] Grep a word within all files in a list that contains $HOME

Issue

I am trying to grep a word on all the files from the list.txt.

list.txt:

$HOME/a.txt
$HOME/b.txt
$HOME/c.txt

When I use

grep -i 'word' $(cat list.txt)

it doesn't realize $HOME. But the following command works!

grep 'word' $HOME/a.txt

Solution

You will need a little bit of magic from envsubst:

$ grep word $(cat list.txt | envsubst)
...


Answered By - Jarek
Answer Checked By - David Goodson (WPSolving Volunteer)