Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get dynamic parameter from text file

Posted on 2014-02-06
4
Medium Priority
?
151 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 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…
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…
Suggested Courses

926 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