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!
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:
Code:
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.
Last edited by Corona688; 09-12-2011 at 01:27 PM..
Hi all,
I'm having an issue about a code i should write...
I have a file... with the following numbers in regex format:
$ cat file_regex.txt
55500508007*
55500218200*
182936*
182929*
4179*
381*
550069341*
So this is a file cointaing some regex... so for each regex i need to... (3 Replies)
so i have been trying to learn how to manipulate text on my own and have gotten stumped...
let's say i have a text file that says (highly simplified):
people ordinary
How would swap the order of the words..
I know i need to use sed and some kind of back reference but cannot make it... (2 Replies)