Solved

get dynamic parameter from text file

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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 …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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