0

I need to get inner text from this string [%L10n.msg('foo')%] so text between [%L10n.msg(' and ')%] so in this example I should get foo.

I found lot of examples but no one of them worked, I tried something like this:

echo "[%L10n.msg('foo')%]" | sed -n -e '/[%L10n.msg(\'/,/\')%]/p'

But I get error

bash: syntax error near unexpected token `)'

UPDATE: Imagine that my string can be inside this strig:

Some ' very [%% ]long ' text [%L10n.msg('foo')%] with lot of [%characters%]

Tested file:

Some ' very [%% ]long ' text [%L10n.msg('foo')%] with lot of [%characters%]
fefe
          <a class="w3-bar-item w3-button" href='/html/html_examples.asp'>HTML Examples</a>

          <a class="w3-bar-item w3-button" href='/html/html_exercises.asp'>HTML Exercises</a>

fefrheerghirlg wgwa g [%L10n.msg('foo')%]


<>"
1

How about

$ echo "[%L10n.msg('foo')%]" | sed "s/\[%L10n.msg('//; s/')%]//"
foo

or, with your NEW input sample,

echo "Some ' very [%% ]long ' text [%L10n.msg('foo')%] with lot of [%characters%]" | sed "s/^.*\[%L10n.msg('//; s/')%].*$//"
foo

or, with input altered for a second time (reads Tested file now), try

sed -n "/^.*\[%L10n.msg('/ {s///; s/')%].*$//;p}" file
foo
foo
  • Thank you and is it possible to do it with file? Like sed "s/^.*\[%L10n.msg('//; s/')%].*$//" filename? – tomsk Nov 14 '18 at 17:19
  • Yes. Just try it. – RudiC Nov 14 '18 at 17:21
  • It doesn't work, I updated question with my testing file, it just print whole file. – tomsk Nov 14 '18 at 17:33
  • No, it doesn't. The two lines that contain the pattern just print foo. The rest is something that comes out of the blue sky. See my edit... – RudiC Nov 14 '18 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.