3つの単一引用符の間にあるテキストを抽出します。

3つの単一引用符の間にあるテキストを抽出します。

私のファイルには次の内容があります

description: '''
        This rule forbids throwing string literals or interpolations. While
        JavaScript (and CoffeeScript by extension) allow any expression to
        be thrown, it is best to only throw <a
        href="https://developer.mozilla.org
        /en/JavaScript/Reference/Global_Objects/Error"> Error</a> objects,
        because they contain valuable debugging information like the stack
        trace. Because of JavaScript's dynamic nature, CoffeeLint cannot
        ensure you are always throwing instances of <tt>Error</tt>. It will
        only catch the simple but real case of throwing literal strings.
        <pre>
        <code># CoffeeLint will catch this:
        throw "i made a boo boo"

        # ... but not this:
        throw getSomeString()
        </code>
        </pre>
        This rule is enabled by default.
        '''

そしてファイルに他の内容もあります。

sed -n "/'''/,/'''/p" $1$1(ファイルはどこにありますか?)を通じて、この部分をシェルスクリプトに抽出しました。

これにより、コンテンツがパッドとして含まれる変数が提供されます。

description: ''' This rule forbids throwing string literals or interpolations. While JavaScript (and CoffeeScript by extension) allow any expression to be thrown, it is best to only throw <a href="https://developer.mozilla.org /en/JavaScript/Reference/Global_Objects/Error"> Error</a> objects, because they contain valuable debugging information like the stack trace. Because of JavaScript's dynamic nature, CoffeeLint cannot ensure you are always throwing instances of <tt>Error</tt>. It will only catch the simple but real case of throwing literal strings. <pre> <code># CoffeeLint will catch this: throw "i made a boo boo" # ... but not this: throw getSomeString() </code> </pre> This rule is enabled by default. '''

今の間にある部分をどのように抽出しますか'''

それとも、複数行ファイルから検索するより良い方法はありますか?

私はMac El Captain 10.11.2とGNU bashバージョン3.2.57(1)-リリース(x86_64-apple-darwin15)を使用しています。

ベストアンサー1

perl -l -0777 -ne "print for /'''(.*?)'''/gs" file

改行文字が続く「」の各ペア間の部分を抽出(および印刷)します。

perl処理が始まる前にファイル全体がメモリで使用されるため、このソリューションは非常に大きなファイルには適していない可能性があります。

おすすめ記事