1

The web page contains this line:

var zx_fn = "string with any possible character";

I download the web page, then I try to to take the part between quotes and store it in a variable

my code:

#!/bin/sh
url="http://www.example.com/..."
content=$(wget -q -O - $url)
var1=$(sed -n '/^var zx_fn = "$/,/^";$/p' "$content")
echo $var1

It doesn't work because it says:

sed: can't read

And it returns the whole page content

Also what's better for this case? grep, awk or sed?

This question has been marked as a duplicate but the other one doesn't clear my doubts, as i need help both with the variable storage and with the regex.

If I follow that answer, the code returns:

Syntax error: redirection unexpected

jww
  • 97,681
  • 90
  • 411
  • 885
markbuster
  • 13
  • 3
  • yes i also need help with the regular expression, also that code doesn't work, it says "Syntax error: redirection unexpected" – markbuster Apr 15 '19 at 22:58
  • I think the question lacks useful information. You did not provide the real URL, you did not provide a sample input or output, and you did not even state the two strings delimiting the text you are trying to extract or replace. Typically folks trying to parse a webpage want text between tags, but it is not clear if you are trying to do that. – jww Apr 15 '19 at 23:32

1 Answers1

0
$ foo='var zx_fn = "string with any possible character";'
$ bar=$(sed -n 's/var zx_fn = "\([^"]*\)";$/\1/p' <<< "$foo")
$ echo "$bar"
string with any possible character

"any possible character" above is assumed to mean "... except double quote". If it can include double quotes then let us know how they are escaped within those strings so we can tell you how to handle them.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185