How can I use a "POSIX BRE" or a "POSIX ERE" regex to match a string
(line or word) that does not have bak
at the end?
I want to do a ls | egrep '<regex>'
to find all files which DO NOT have bak
at the end of the filename.
For example, if there are three files file1
, file2_bak
, and bak_file3
, the regex should match only file1
and bak_file3
(but not file2_bak
).
I know that this can be done with ls | grep -v 'bak$'
, but I want to do this without using -v
option for grep
or egrep
. I don’t want to use -v
because this is just a theoretical/academic question on POSIX regexes.
This is how I match the filenames which DO HAVE bak
at the end:
$ ls | egrep 'bak$'
file2_bak
$
The above regex, bak$
, matches all strings that DO HAVE bak
at the end. But how can I write a regex which matches all strings that do not have bak
at the end?
ls
orgrep
tools, but only formulated in terms of Regular Expressions. (I seem to have been not the only one misleaded by your question.)-v
isn't ok (because that's the "normal" way to do what you ask with grep).regex
part that is why I did not want to use-v
. It was just a theoretical/academical question onregex
. Asgrep
is the only utility I have used so far to useregex
my question somehow had agrep
command in it. For practical puprpose even I will do-v
and keep it simple and clear. I am practising posix regex so i was just trying different things to test myself ...