テキストファイルから指定された2つの文字列の間のすべてのテキストを削除する必要があります。文字列は別の行にあってもかまいません。たとえば、次のテキストファイルでは
@article{ginsberg_lifespan_2018,
title = {On the lifespan of three-dimensional abstract gravity water waves with vorticity},
abstract = {test1
test2 abstract {NS}
test3},
language = {en},
urldate = {2018-12-05},
author = {Ginsberg, Daniel},
month = dec,
year = {2018}
}
@article{higaki_two-dimensional_2017,
title = {On the two-dimensional steady {Navier}-{Stokes} equations related to flows around a rotating obstacle},
abstract = {We study the two-dimensional stationary Navier-Stokes equations with rotating effect in the whole space. The unique existence and the asymptotics of solutions are obtained without the smallness assumption on the rotation parameter.},
journal = {arXiv:1703.07372 [math]},
author = {Higaki, Mitsuo and Maekawa, Yasunori and Nakahara, Yuu},
month = mar,
year = {2017},
note = {arXiv: 1703.07372},
keywords = {Mathematics - Analysis of PDEs}
}
この文字列を含む常に行の末尾にあるものabstract =
とaの間のすべての項目を削除したいと思います。},
つまり、次のような出力が必要です。
@article{ginsberg_lifespan_2018,
title = {On the lifespan of three-dimensional abstract gravity water waves with vorticity},
language = {en},
urldate = {2018-12-05},
author = {Ginsberg, Daniel},
month = dec,
year = {2018}
}
@article{higaki_two-dimensional_2017,
title = {On the two-dimensional steady {Navier}-{Stokes} equations related to flows around a rotating obstacle},
journal = {arXiv:1703.07372 [math]},
author = {Higaki, Mitsuo and Maekawa, Yasunori and Nakahara, Yuu},
month = mar,
year = {2017},
note = {arXiv: 1703.07372},
keywords = {Mathematics - Analysis of PDEs}
}
この種の質問があることを知って、公開されたソリューションを試してみました。たとえば、私は
perl -0777 -pe 's/abstract = .*},\n/\n/gs'
abstract =
ただし、これにより、連続する項目ではなく、最初の項目と最後の項目の間のテキストが削除されます},
。これは私が得たものです。
@article{ginsberg_lifespan_2018,
title = {On the lifespan of three-dimensional gravity water waves with vorticity},
keywords = {Mathematics - Analysis of PDEs}
}
必要な結果を得るには、このコマンドをどのように変更する必要がありますか?
ベストアンサー1
$ sed '/abstract = .*},$/d; /abstract = /,/},$/d' <file
@article{ginsberg_lifespan_2018,
title = {On the lifespan of three-dimensional abstract gravity water waves with vorticity},
language = {en},
urldate = {2018-12-05},
author = {Ginsberg, Daniel},
month = dec,
year = {2018}
}
@article{higaki_two-dimensional_2017,
title = {On the two-dimensional steady {Navier}-{Stokes} equations related to flows around a rotating obstacle},
journal = {arXiv:1703.07372 [math]},
author = {Higaki, Mitsuo and Maekawa, Yasunori and Nakahara, Yuu},
month = mar,
year = {2017},
note = {arXiv: 1703.07372},
keywords = {Mathematics - Analysis of PDEs}
}
まず、1行のabstract
項目全体を削除しようとしますが、それでも機能しない場合は、複数行の項目を削除しようとしますabstract
。複数行エントリは、インクルードabstract =
行から終わる次の行までの行セットです},
。
注釈付きsed
スクリプト:
/abstract = .*},$/d # delete complete abstract line, skip to next input line
/abstract = /,/},$/d # delete multi-line abstract entry
たとえば、開始文字列をより具体的に指定する必要がある場合は、これらの式の一部を代わり^[[:blank:]]*abstract
に使用できます。この行の前にはスペースまたはタブのみがabstract
許可されています。abstract =