I have a file that contains paths - looks like this:
/Users/a/Desktop
/Users/a/Documents
/Users/a/Documents/Work
What would be the easiest way to remove all lines that contain the current directory ($PWD
)?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communitygrep -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)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