Reputation: 1
I am fairly new at this curl scripting and I am looking for a way to paste a text from a token like value when I hit a specific site.
Currently I have:
echo $a_opensite | grep -E -o 'value=\".*==.*' | awk '{print $1}' >
/Users/MZComputer/Downloads/10Step/VIEWSTATE_file;
which writes the value below in a file called:
VIEWSTATE_file****value="bdC7M0jCKxJNSfHjUVv+4MMt3/ysSLviYkIQnnpntK3qNCarg7H012UIllu+XBDepbWYWktNdf3EBgd3xd0...UVv"****
BUT the text value="
is what I am able to use to get the correct token. However, I do not want to include the value="...."
in the file, just want to include the text within the quotation marks - excluding the quotation marks themselves.
Any ideas how I can achieve?
Upvotes: 0
Views: 100
Reputation: 44023
Assuming GNU grep, I'd use its -P
option and Perl-style lookbehind/lookahead expressions. For example:
$ echo 'foo value="something interesting" bar' | grep -Po '(?<=value=\").*?(?=\")'
something interesting
The interesting bits are:
(?=\")
-- this is a lookahead expression. It matches the empty string iff it is followed by the specified regex, in this case \"
. In the example above it'll match the empty string just before " bar
at the end of the supplied input.(?<=value=\")
-- this is a lookbehind expression. It matches the empty string iff it is preceded by the specified regex, in this case value=\"
In the example above, it'll match the empty string just before something interesting
..*?
matches any sequence of characters non-greedily, which is to say that if the line reads value="stuff" garbage="more stuff"
it'll match just stuff
and not stuff" garbage="more stuff
.Combined with the -o
option, this will isolate the string between value="
and the next "
.
Upvotes: 0
Reputation: 4809
Use the following line:
echo $a_opensite | grep -E -o 'value=\".==.' | awk '{print $1}' | sed 's/value="\([^"]*\)"/\1/' > /Users/MZComputer/Downloads/10Step/VIEWSTATE_file;
Upvotes: 1