Comparing GREP to BASH REGEX
-
@scottalanmiller I might do that. Let's say I have a file that has the following line of text
aabbcc
in a file calledabc.txt
. (Using part of their example)If I do
grep .cc abc.txt
a result is returned, since I've learned that the dot stands for one character. However, if I dogrep ?cc abc.txt
no results are returned. I thought the ? stands for zero or one character. If that's true, why would it not return a result? -
I thought that \? meant that.
-
The character ‘.’ matches any single character except newline.
‘\+’
indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
‘\?’
indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
‘+ and ?’
match themselves. -
So you are searching for an actual question mark, not what you think that you are. I think that your definition of what a ? is is flawed.
-
@EddieJennings said in What Are You Doing Right Now:
@scottalanmiller I might do that. Let's say I have a file that has the following line of text
aabbcc
in a file calledabc.txt
. (Using part of their example)If I do
grep .cc abc.txt
a result is returned, since I've learned that the dot stands for one character. However, if I dogrep ?cc abc.txt
no results are returned. I thought the ? stands for zero or one character. If that's true, why would it not return a result?Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and )
lose their special meaning; instead use the backslashed versions ?,
+, {, |, (, and ).or use egrep to get the extended regular expressions.
-
@scottalanmiller I'm doing this the wrong, but before I find some kind of documentation, I'm experimenting
I wonder if it's something specific about grep, since the following seems to be true.
ls
file1.txt file2.txt file3.txt
ls file?.txt
file1.txt file2.txt file3.txt
ls file..txt
no result. -
@EddieJennings said in What Are You Doing Right Now:
@scottalanmiller I'm doing this the wrong, but before I find some kind of documentation, I'm experimenting
I wonder if it's something specific about grep, since the following seems to be true.
ls
file1.txt file2.txt file3.txt
ls file?.txt
file1.txt file2.txt file3.txt
ls file..txt
no result.You are mixing BASH and grep. Those are two different things. The REGEX of one does not apply to the other. REGEX is not a universal constant.
-
Every system... PowerShell, Perl, Python, Ruby, BASH, grep... they all have unique REGEX. REGEX just means "regular expression" and does not refer to a specific syntax, but a general concept. So the issue is that what is a REGEX standard for BASH (which is what you are using with ls) is not REGEX for grep.
-
How did we do on speed and completeness compared to the academy site?
-
You'll find SED REGEX to be the other big one to learn.
-
For this particular question, you're asking me to divide by zero, for I haven't seen a response.
The explanation of the fact that REGEX doesn't represent a universal syntax is lacking in the Linux Essentials course. Since, that ? mark was used (with the definition I stated earlier) with
ls
examples, and the beginning of the REGEX module says "you've used this before but didn't know it was REGEX." The module itself uses both grep and BASH (ls
), but no mention of the fact there are differences, which can lead to confusion. -
That makes sense. They did not explain that well. And it isn't a Linux concept so even weirder.
-
This post is deleted!