Reverse regex logic

Hi,

I'm trying to reverse regex logic to use it in grep command. I would like to grep a string within a file that contains regex.
For example
file example.txt contains line:
match*

And I would like to find it using
grep match123 example.txt

Is it possible?
Thank you very much for all answers!

Regards,
Igor

That exact command won't work of course, but perhaps:

echo match123 | grep -f matchfile

The -f tells it to interpret matchfile file as a file full of regexes, one per line.

Hi Corona688, thanks for quick reply!

It's not working this way. Problem is that I nowhere found single example of same logic (to match exact string with regex or any wildcard). Maybe I just expect too much...

Ah. match* If interpreted as a regex, the * here matches 0 or more h chars, so you'd match 'match', 'matchh', 'matchhhh' and so forth. If this isn't what you want, then this isn't a regex, and grep can't handle it. It looks more like a shell glob...

To match one or more of any chars your string would need to be match.*

---------- Post updated at 09:21 AM ---------- Previous update was at 09:15 AM ----------

If you have BASH or KSH:

STR="match123"

OLDIFS="$IFS"
IFS=""
while read LINE
do
        [ -z "$LINE" ] && continue # Ignore blank lines
        [[ "${STR}" == $LINE ]] && echo "$LINE"
done < globfile
IFS="$OLDIFS"

Lines like match* should match the "match123". atch* wouldn't. *atch* still would.

Hi,
Try this untested one,

grep "match\*" file

Cheers,
Ranga:-)