I have a file that contains paths - looks like this:


What would be the easiest way to remove all lines that contain the current directory ($PWD)?

1 Answer 1

grep -v "^$PWD$" FILE-LIST
  • -v inverses the search, so only non-matching lines are printed
  • ^...$ ensures that the pattern only matches the whole line (otherwise all subdirectories of $PWD would got filtered as well)
  • 1
    Awesome, that's perfect - simple and works! Dec 25, 2018 at 12:38
  • 3
    See also the -x option which does the ^ and $ for you
    – Jeff Schaller
    Dec 25, 2018 at 13:20
  • 1
    grep -xvF -- "$PWD" should be safe, lest the present working directory name comprise grep regex metachars and/or options. Dec 26, 2018 at 4:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .