2

次のように、多くの TeX マークアップを含むファイルがあります。

The fish ate 20\percent more food than the bear.
The fish ate \the\number\percent more food than the bear.

\percentTeXコードであるテキストを削除して、スペースに置き換えたいと思います。

  • マークアップは常に . で始まります\
  • マークアップの後には常にスペース、{、または別の が続き\ます。
  • \、ファイル内の他の状況では使用されません。

で始まり\、その後にスペース、{、または別の が続くこれらのアイテムの外観を削除するにはどうすればよい\ですか?

4

1 に答える 1

3

次の perl コマンドを使用できます。

perl -pe 's#\\[^ \\{]+# #g' file.txt

またはsedを使用:

sed -E 's#\\[^ \\{]+# #g' file.txt

または、-E がサポートされていない場合:

sed -r 's#\\[^ \\{]+# #g' file.txt

出力

The fish ate 20  more food than the bear.
The fish ate     more food than the bear.
于 2012-05-11T23:49:57.370 に答える