Parsing Amazon Access Log file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adarwish
    New Member
    • Dec 2011
    • 9

    Parsing Amazon Access Log file

    Please Help me in parsing Amazon s3 Access log file. using .NET C#

    the is an example for a row from the file

    Code:
    e9393f8b003f121858490f62e9339f29ab5919261b8da33746cedb356e29f774 alzwad [18/Jan/2012:22:27:24 +0000] 41.155.169.152 - 6A70EBA012DB351A REST.GET.OBJECT Me/mefiles/videos/icons/240x320/18-1-12-9-19-56-egypt-movie3.jpg "GET /Me/mefiles/videos/icons/240x320/18-1-12-9-19-56-egypt-movie3.jpg?id=01229466985&ph=01229466985&width=240&high=320 HTTP/1.1" 200 - 1590 1590 34 33 "-" "Nokia2700c-2/2.0 (07.15) Profile/MIDP-2.1 Configuration/CLDC-1.1 UNTRUSTED/1.0" -
    the parameters are separated with a (Space, Double Quotes and Square Brackets)

    can any one tell me how to parse it.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There is no "Space, Double Quotes and Square Brackets" combination in the row you posted.

    Comment

    • adarwish
      New Member
      • Dec 2011
      • 9

      #3
      This is an example

      "GET /Me/mefiles/videos/icons/240x320/18-1-12-9-19-56-egypt-movie3.jpg?id=0 1229466985&ph=0 1229466985&widt h=240&high=320 HTTP/1.1"

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        That has no space followed by double quote followed by square bracket. If that is truly what you want, then you need to redescribe what you want because that's not what you said in the first post.

        Comment

        • adarwish
          New Member
          • Dec 2011
          • 9

          #5
          Dear Rabbit,

          thanks for replying.

          Actually the problem in: if i split on spaces i will found some parameters contains spaces but surrounded with double quotes or square brackets

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            What it sounds like is you don't want to split on spaces at all but on double quotes and brackets.

            Comment

            • adarwish
              New Member
              • Dec 2011
              • 9

              #7
              i want to split on spaces but the problem is some parameters contains spaces but surrounded with double quotes or square brackets

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Then split on the quotes and brackets first. Then split on spaces on those that remain.

                Comment

                • danp129
                  Recognized Expert Contributor
                  • Jul 2006
                  • 323

                  #9
                  Code:
                  using System.Text.RegularExpressions;
                  using System.Text;
                  ////////
                  private void Button1_Click(System.Object sender, System.EventArgs e)
                  {
                  	string logLine = "e9393f8b003f121858490f62e9339f29ab5919261b8da33746cedb356e29f774 alzwad [18/Jan/2012:22:27:24 +0000] 41.155.169.152 - 6A70EBA012DB351A REST.GET.OBJECT Me/mefiles/videos/icons/240x320/18-1-12-9-19-56-egypt-movie3.jpg \"GET /Me/mefiles/videos/icons/240x320/18-1-12-9-19-56-egypt-movie3.jpg?id=01229466985&ph=01229466985&width=240&high=320 HTTP/1.1\" 200 - 1590 1590 34 33 \"-\" \"Nokia2700c-2/2.0 (07.15) Profile/MIDP-2.1 Configuration/CLDC-1.1 UNTRUSTED/1.0\" -";
                  	Regex re = new Regex("(\\S+) (\\S+) \\[(.*?)\\] (\\S+) (\\S+) (\\S+) (\\S+) (\\S+) \"([^\"]+)\" (\\S+) (\\S+) (\\S+) (\\S+) (\\S+) (\\S+) \"([^\"]+)\" \"([^\"]+)\"", RegexOptions.IgnoreCase);
                  	RegularExpressions.Match reMatch = re.Matches(logLine).Item(0);
                  	for (int i = 1; i <= reMatch.Groups.Count - 1; i += 1) {
                  		Debug.Print(reMatch.Groups(i).Captures(0).Value.Trim('"'));
                  	}
                  }
                  The regex pattern is from https://forums.aws.amazon.com/messag...ssageID=186803

                  Comment

                  • adarwish
                    New Member
                    • Dec 2011
                    • 9

                    #10
                    Thanks danp129 it Worked fine

                    Comment

                    Working...