Solved

get dynamic parameter from text file

Posted on 2014-02-06
4
134 Views
Last Modified: 2014-02-09
hi

i have a simple log text file (access_log ) that can have a url inside :

 "POST / HTTP/1.1" 302 3064 "http://localhost/Succeeded.html?user=yyy" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)

i want to get the user which is aftet "= " i mean  yyy
the yyy is dynamic and other is state.

i have tried to use this:

username=`cat /access_log | grep -P '(?<=Succeeded.html?user=)[A-Za-z0-9]*'`

 didn't work

please help

thanks a lot
0
Comment
Question by:weissman
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39838874
Try this:

username=cat /access_log | grep 'Succeeded.html?user=[A-Za-z0-9]*' | cut -d'=' -f 2

grep will retain only the lines where you have that link, while cut will give you the part after "="

LE: see here for a discussion on capturing groups with grep.

HTH,
Dan
0
 

Author Comment

by:weissman
ID: 39838917
hi Dan,

thank you very much for helping i think it is almost perfect

the result is:

yyy "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"

whrere yy is the user i need.
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39838936
OK, try this:

username=cat /access_log | grep 'Succeeded.html?user=[A-Za-z0-9]*\"' | cut -d'=' -f 2

This should stop matching at the first "
0
 

Author Closing Comment

by:weissman
ID: 39845019
Thanks  ... it give me the  first  occurance
I need the last ...can I use tail for that.
Thanks very much.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now