Solved

get dynamic parameter from text file

Posted on 2014-02-06
4
135 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

948 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

23 Experts available now in Live!

Get 1:1 Help Now