
次の行があります。
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
grep
Perl互換正規表現(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
答え2
grepのような正規表現が欲しいと思います。そんなことgrep 'VAR\("[A-z0-9]*"\)'
。しかし、あなたの場合は、このすべての\"は機能しません。おそらく次のようになります。grep '(^VAR(\")[A-z0-9](^\"))' | grep 'VAR\(\\"[A-z0-9]*\\"\)'
私はgrepをあまりにも長く使用していませんでした。 :)