2つの文字列間の文字列を取得する

2つの文字列間の文字列を取得する

この文字列から[%L10n.msg('foo')%]内部テキストを取得する必要が[%L10n.msg('あるため、')%]この例ではインポートする必要がありますfoo

多くの例を見つけましたが、そのうち何も機能しませんでした。次のように試しました。

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

しかし、エラーが発生しました。

bash:予期しないマーカー ")"の近くに構文エラーがあります。

修正する: 私の文字列が次の文字列にある可能性があると想像してください。

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

テストファイル:

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

どうですか?

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

または、新しい入力サンプルを使用して

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

または、入力を2番目に変更します(読み取りテストファイル今)試してみてください

sed -n "/^.*\[%L10n.msg('/ {s///; s/')%].*$//;p}" file
foo
foo

おすすめ記事