Unix Shell - Simple regex ...

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2006 > Simple regex ...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Simple regex ...
daraburke78@gmail.com

2006-02-20, 5:54 pm

So I'm stuck on a simple regex ... again ...
I'm parsing a form data for a curl script

name="__VIEWSTATE" value="dDwtsdkf...="

.... I want the VIEWSTATE data ...

dDwtsdkf...=

here's my regex

/\("__VIEWSTATE" value="\)\(.*\)[^"]/\2

.... I don't know why that doesn't work...

help pls ...

Chris F.A. Johnson

2006-02-20, 5:54 pm

On 2006-02-20, daraburke78@gmail.com wrote:
> So I'm stuck on a simple regex ... again ...
> I'm parsing a form data for a curl script
>
> name="__VIEWSTATE" value="dDwtsdkf...="
>
> ... I want the VIEWSTATE data ...
>
> dDwtsdkf...=
>
> here's my regex
>
> /\("__VIEWSTATE" value="\)\(.*\)[^"]/\2
>
> ... I don't know why that doesn't work...


In what context are you using it?

sed 's/.*name="__VIEWSTATE".*value=\"\([^"]*\)".*/\1/'

awk -F'"' '/name="__VIEWSTATE"/ {print $4}'

while IFS= read -r line
do
eval "$line" ## Don't do this if you don't trust the file
[ "$name" == "__VIEWSTATE" ] && break
done
## $value contains dDwtsdkf...=

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
daraburke78@gmail.com

2006-02-20, 5:54 pm

Thanks Chris,

I really appreciate your help. One more question pls ...

What if I want to disregard the output from every line where I don't
match the pattern. In otherwords, to only have the

dDwtsdkf...=

.... in the output file ? .... I hope I'm not being too greedy here.

Chris F.A. Johnson

2006-02-20, 5:54 pm

On 2006-02-20, daraburke78@gmail.com wrote:
> Thanks Chris,
>
> I really appreciate your help. One more question pls ...


Please read <http://cfaj.freeshell.org/google>.

> What if I want to disregard the output from every line where I don't
> match the pattern. In otherwords, to only have the
>
> dDwtsdkf...=
>
> ... in the output file ? .... I hope I'm not being too greedy here.


What output file? Which script?


--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
daraburke78@gmail.com

2006-02-21, 7:49 am

Thanks chris,

sorry about the confusion. I'm writing a regex to parse out a viewstate
variable as below. Your regex parsed it out fine, but it just kinda
dumps the viewstate back into the rest of the text.

I'm looking for a file containing just the viewstate value and nothing
else. This is my sed value at the moment

sed 's/.*name="__VIEWSTATE".*value=\"\([^"]*\)".*/\1/'
full_webpage_text > viewstate_only_text

I've tried sed -n - but that just outputs nothing ....

Cheers


Chris F.A. Johnson wrote:
> On 2006-02-20, daraburke78@gmail.com wrote:
>
> In what context are you using it?
>
> sed 's/.*name="__VIEWSTATE".*value=\"\([^"]*\)".*/\1/'
>
> awk -F'"' '/name="__VIEWSTATE"/ {print $4}'
>
> while IFS= read -r line
> do
> eval "$line" ## Don't do this if you don't trust the file
> [ "$name" == "__VIEWSTATE" ] && break
> done
> ## $value contains dDwtsdkf...=
>
> --
> Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
> Shell Scripting Recipes: | My code in this post, if any,
> A Problem-Solution Approach | is released under the
> 2005, Apress | GNU General Public Licence


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com