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?
lsorgreptools, but only formulated in terms of Regular Expressions. (I seem to have been not the only one misleaded by your question.)-visn't ok (because that's the "normal" way to do what you ask with grep).regexpart that is why I did not want to use-v. It was just a theoretical/academical question onregex. Asgrepis the only utility I have used so far to useregexmy question somehow had agrepcommand in it. For practical puprpose even I will do-vand keep it simple and clear. I am practising posix regex so i was just trying different things to test myself ...