ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Comparing GREP to BASH REGEX

    Water Closet
    4
    13
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • RomoR
        Romo @EddieJennings
        last edited by

        @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 aabbccin a file called abc.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 do grep ?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.

        1 Reply Last reply Reply Quote 1
        • EddieJenningsE
          EddieJennings @scottalanmiller
          last edited by

          @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.

          scottalanmillerS 1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @EddieJennings
            last edited by

            @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.

            1 Reply Last reply Reply Quote 1
            • scottalanmillerS
              scottalanmiller
              last edited by

              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.

              EddieJenningsE 1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller
                last edited by

                How did we do on speed and completeness compared to the academy site?

                1 Reply Last reply Reply Quote 0
                • scottalanmillerS
                  scottalanmiller
                  last edited by

                  You'll find SED REGEX to be the other big one to learn.

                  1 Reply Last reply Reply Quote 1
                  • EddieJenningsE
                    EddieJennings
                    last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller
                      last edited by

                      That makes sense. They did not explain that well. And it isn't a Linux concept so even weirder.

                      1 Reply Last reply Reply Quote 0
                      • A
                        aidan_walsh
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post