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

    Grep help

    Scheduled Pinned Locked Moved IT Discussion
    17 Posts 3 Posters 980 Views
    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.
    • L
      Laksh1999 @scottalanmiller
      last edited by

      @scottalanmiller said in Grep help:

      I'm not sure that I understand? Can you show a sample of five or six different ticket numbers?

      example the txt file have

      D00000000
      D00000001
      D00000002
      D00000003

      Theses are the tickets numbers which is available in the txt file where i am in need to grep the ticket number only from the txt file

      JaredBuschJ 1 Reply Last reply Reply Quote 0
      • JaredBuschJ
        JaredBusch @Laksh1999
        last edited by

        @laksh1999 Because you are attempting to use regular expressions with a tool that does not know WTF those are.
        man grep is a wonderful thing.
        If you are going to keep asking questions, you should learn to do a little basic reading.

        but to spoon feed you...

        # return lines with an A or D followed by 8 digits.
        grep [AD][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
        

        Sample:

        stuff 1 A00000000 more stuff 1
        stuff 2 B0000001 more stuff 2
        stuff 3 C00000002 more stuff 3
        stuff 4 D00000003 more stuff 4
        stuff 5 E00000002 more stuff 5
        

        Result:

        cat test.txt | grep [AD][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
        stuff 1 A00000000 more stuff 1
        stuff 4 D00000003 more stuff 4
        
        L 1 Reply Last reply Reply Quote 0
        • L
          Laksh1999 @JaredBusch
          last edited by

          @jaredbusch said in Grep help:

          @laksh1999 Because you are attempting to use regular expressions with a tool that does not know WTF those are.
          man grep is a wonderful thing.
          If you are going to keep asking questions, you should learn to do a little basic reading.

          but to spoon feed you...

          # return lines with an A or D followed by 8 digits.
          grep [AD][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
          

          Sample:

          stuff 1 A00000000 more stuff 1
          stuff 2 B0000001 more stuff 2
          stuff 3 C00000002 more stuff 3
          stuff 4 D00000003 more stuff 4
          stuff 5 E00000002 more stuff 5
          

          Result:

          cat test.txt | grep [AD][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
          stuff 1 A00000000 more stuff 1
          stuff 4 D00000003 more stuff 4
          

          This does not work for me.I have tried this as well.I am not asking for spoon feeding for the same.

          i have the json file with "id" ="D00000000" and "id"="V000000000" and i too have some id with encrypted data.i need to get only the D and V numbers and arranged in order from the json file which i have downloaded as .txt

          JaredBuschJ 2 Replies Last reply Reply Quote 0
          • JaredBuschJ
            JaredBusch @Laksh1999
            last edited by

            @laksh1999 said in Grep help:

            json file

            Then use json tools FFS.
            man jq

            cat wtf.txt | jq *.id
            
            L 1 Reply Last reply Reply Quote 0
            • JaredBuschJ
              JaredBusch @Laksh1999
              last edited by

              @laksh1999 said in Grep help:

              This does not work for me.

              I would love to see proof because I just showed you proof it does work.

              L 1 Reply Last reply Reply Quote 0
              • L
                Laksh1999 @JaredBusch
                last edited by

                @jaredbusch said in Grep help:

                @laksh1999 said in Grep help:

                This does not work for me.

                I would love to see proof because I just showed you proof it does work.

                 cat newdata.txt | grep [V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]] 
                zsh: no matches found: [V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
                
                JaredBuschJ 1 Reply Last reply Reply Quote 0
                • L
                  Laksh1999 @JaredBusch
                  last edited by

                  @jaredbusch said in Grep help:

                  @laksh1999 said in Grep help:

                  json file

                  Then use json tools FFS.
                  man jq

                  cat wtf.txt | jq *.id
                  
                  cat newdata.txt | jq *.id
                  zsh: no matches found: *.id
                  
                  JaredBuschJ 1 Reply Last reply Reply Quote 0
                  • JaredBuschJ
                    JaredBusch @Laksh1999
                    last edited by JaredBusch

                    @laksh1999 said in Grep help:

                    @jaredbusch said in Grep help:

                    @laksh1999 said in Grep help:

                    json file

                    Then use json tools FFS.
                    man jq

                    cat wtf.txt | jq *.id
                    
                    cat newdata.txt | jq *.id
                    zsh: no matches found: *.id
                    

                    You didn't bother to read the man file.. i pulled that out of my ass from memory...

                    the correct syntax is jq '.id

                    but as this point I doubt you have the data you think you have in your text file.

                    JaredBuschJ 1 Reply Last reply Reply Quote 0
                    • JaredBuschJ
                      JaredBusch @JaredBusch
                      last edited by JaredBusch

                      @jaredbusch said in Grep help:

                      the correct syntax is jq '.id'

                      I'm also assuming that id is one of the json keys based on your first post.

                      L 1 Reply Last reply Reply Quote 0
                      • JaredBuschJ
                        JaredBusch @Laksh1999
                        last edited by

                        @laksh1999 said in Grep help:

                        @jaredbusch said in Grep help:

                        @laksh1999 said in Grep help:

                        This does not work for me.

                        I would love to see proof because I just showed you proof it does work.

                         cat newdata.txt | grep [V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]] 
                        zsh: no matches found: [V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
                        

                        no one knows WTF you have in newdata.txt....

                        cat > test.txt << EOF
                        stuff 1 A00000000 more stuff 1
                        stuff 2 B00000001 more stuff 2
                        stuff 3 C00000002 more stuff 3
                        stuff 4 D00000003 more stuff 4
                        stuff 5 E00000002 more stuff 5
                        EOF
                        

                        then

                        cat test.txt | grep [AD][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
                        

                        3a3ec045-a5a6-4a91-aeeb-a9a0e5aa4ff8-image.png

                        L 1 Reply Last reply Reply Quote 0
                        • L
                          Laksh1999 @JaredBusch
                          last edited by

                          @jaredbusch said in Grep help:

                          @jaredbusch said in Grep help:

                          the correct syntax is jq '.id

                          I'm also assuming that id is one of the json keys based on your first post.

                          There are more id values are there in the txt file

                          Example)
                          This id value example is only for the 1 tickets
                          "id"="D00000000"
                          "id" ="V00000000"
                          "id"="eeeeeee-eeeeee-eeeee-eeeee"
                          "id"="eadsga-ereagag"

                          i just want to grep only D0000000 and V000000 values for each tickets.There are around 5000 tickets are there and each for more id for one ticket

                          JaredBuschJ 1 Reply Last reply Reply Quote 0
                          • L
                            Laksh1999 @JaredBusch
                            last edited by

                            @jaredbusch said in Grep help:

                            @laksh1999 said in Grep help:

                            @jaredbusch said in Grep help:

                            @laksh1999 said in Grep help:

                            This does not work for me.

                            I would love to see proof because I just showed you proof it does work.

                             cat newdata.txt | grep [V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]] 
                            zsh: no matches found: [V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
                            

                            no one knows WTF you have in newdata.txt....

                            cat > test.txt << EOF
                            stuff 1 A00000000 more stuff 1
                            stuff 2 B00000001 more stuff 2
                            stuff 3 C00000002 more stuff 3
                            stuff 4 D00000003 more stuff 4
                            stuff 5 E00000002 more stuff 5
                            EOF
                            

                            then

                            cat test.txt | grep [AD][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]
                            

                            3a3ec045-a5a6-4a91-aeeb-a9a0e5aa4ff8-image.png

                            This worked for me now

                            cat test.txt | grep '[V][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]'
                            
                            1 Reply Last reply Reply Quote 0
                            • JaredBuschJ
                              JaredBusch @Laksh1999
                              last edited by

                              @laksh1999 said in Grep help:

                              want to grep

                              no you don't.

                              FFS how many times do I have to tell you.

                              Your data is json, use fucking jsontools.

                              jq is extremely powerful. Use it to correctly query your json data to get the result you need.

                              1 Reply Last reply Reply Quote 1
                              • JaredBuschJ
                                JaredBusch
                                last edited by

                                https://www.cloudsavvyit.com/1877/how-to-work-with-json-on-the-command-line/

                                1 Reply Last reply Reply Quote 0
                                • 1 / 1
                                • First post
                                  Last post