Solved

get dynamic parameter from text file

Posted on 2014-02-06
4
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

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 35

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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

623 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