Issue
On Debian Linux:
I'm wanting to do a search and then filter it by those lines that do NOT begin with "/mnt/c/" or "/mnt/x/", my current disks (I'm working on WSL).
So then I write: `locate $str | grep /[!cx]
I learned a bit about wildcards but I don't know what I'm doing wrong. Any help would be appreciated.
Solution
You need to use grep
regexes rather than shell wildcards:
locate "$str" | grep -v '^/mnt/[cx]/'
Put quotes around $variable
as a matter of routine — there are occasions not to do so, but they are rare.
The -v
option to grep
means "print the lines that don't match". The regex '^/mnt/[cx]/'
means lines that start with /mnt/c/
or /mnt/x/
, so in conjunction with -v
that means "only print lines that don't start with /mnt/c/
or /mnt/x/
.
I'm blithely assuming that the locate
command provides the data you want to filter.
Answered By - Jonathan Leffler Answer Checked By - Marie Seifert (WPSolving Admin)