文字列から1つ以上のパターンを抽出します。

文字列から1つ以上のパターンを抽出します。

次の行があります。

function( "((2 * VAR(\"xxx\")) - VAR(\"yyy\"))" ?name "name" ?plot t ?save t ?evalType 'point)
function("value(res VAR(\"zzz\"))" ?name "othername" ?plot t ?save t ?evalType 'point)

また、VAR関数で定義された文字列を出力するコマンドを探したいと思います。つまり:

xxx yyy
zzz

試してみましたが、sed私が理解している限り、貪欲ではない方法ではできません。

ベストアンサー1

grepPerl互換正規表現(PCRE)をサポートするプログラムがある場合は、次のものを使用できます。

grep -Po 'VAR\(\\"\K[^\\]*'

または(もう少し対称的です。振り返ってプレビューを使用してください)

grep -Po '(?<=VAR\(\\").*?(?=\\")'

前任者。

$ grep -Po 'VAR\(\\"\K[^\\]*'
function( "((2 * VAR(\"xxx\")) - VAR(\"yyy\"))" ?name "name" ?plot t ?save t ?evalType 'point)
function("value(res VAR(\"zzz\"))" ?name "othername" ?plot t ?save t ?evalType 'point)
xxx
yyy
zzz

前任者。

$ grep -Po '(?<=VAR\(\\").*?(?=\\")'
function( "((2 * VAR(\"xxx\")) - VAR(\"yyy\"))" ?name "name" ?plot t ?save t ?evalType 'point)
function("value(res VAR(\"zzz\"))" ?name "othername" ?plot t ?save t ?evalType 'point)
xxx
yyy
zzz

おすすめ記事