I want to grep a file, and I want to get all the lines that have a certain environment variable (to be exact, $PWD).Of course, using justcat file | grep '/'$PWD'/'is not working, since $PWD contains slashes.I am trying to figure out how to do it correctly, but I come up only with weird and over-complicated solutions. What's some simple way to do this?
How to grep for something that's in an environment variable and has a forward slash?
bash;grep
Just use double quote instead of single quote, and you don't have to use cat (See UUOC):grep -F -- $PWD fileAnd remember that without -F, $PWD would be treated as a regular expression as opposed to a string to be looked for in the file.