ファイル全体のすべての行で特定のコンテキストの文字を置き換える方法は?

ファイル全体のすべての行で特定のコンテキストの文字を置き換える方法は?

次の形式の数百の英語の構文を含む大きなファイルがあります。

\phrase
{.   .    .     *     *   }
{I shoul-d've stayed home.}
{aɪ ʃʊd‿əv ˈsteɪd ˈhoʊm.} <- only replace on this line

\phrase
{ .   .   *  }
{Did you eat?}
{dɪdʒjʊʷˈit? ↗} <- only replace on this line

\phrase
{ *    .  *    .    *  .  .    .     *   .  }
{Yeah, I made some pas-ta if you're hun-gry.}
{ˈjɛə, aɪ ˈmeɪd səm ˈpɑ stəʷɪf jər ˈhʌŋ gri.} <- only replace on this line

LaTeX.texファイルです。r各音声記号(音声記号は対応する行の後の\phrase3行ごとに意味)のすべての文字を記号(16進コード)に置き換えたいと思います。ɹU+0279

Emacsで手動で行うのは私にとって面倒です。どういうわけかこの行を見つけて自動的に交換する方法があるかどうか疑問に思います。

例外なくすべてのr文字を置き換える必要がɹありますが、音声記号のみを置き換える必要があり、r英語/非音域テキストはそのまま残ります。

スクリプトなどを使用してこれを実行できますか?私の文書には改行がないので、戦士はいつも\phrase。ありがとうございます!

ベストアンサー1

awkバージョン(1行に入れることができるメタファイルが必要です)

awk '/\\phrase/ { p=NR ; } 
     NR == p+3 { gsub("r","ɹ")  ; } 
    {print;} ' old-file.tex > new-file.tex

どこ

  • /\\phrase/ { p=NR ; }発生するpすべての行番号に設定されます\phrase
  • NR == p+3 { gsub("r","ɹ") ; } その後、ライン 3 で交換を行います。
  • {print;}すべての行を印刷します。

以下はサンプルを提供します。 (参考ɹeplace

\phrase
{.   .    .     *     *   }
{I shoul-d've stayed home.}
{aɪ ʃʊd‿əv ˈsteɪd ˈhoʊm.} <- only ɹeplace on this line

\phrase
{ .   .   *  }
{Did you eat?}
{dɪdʒjʊʷˈit? ↗} <- only ɹeplace on this line

\phrase
{ *    .  *    .    *  .  .    .     *   .  }
{Yeah, I made some pas-ta if you're hun-gry.}
{ˈjɛə, aɪ ˈmeɪd səm ˈpɑ stəʷɪf jəɹ ˈhʌŋ gɹi.} <- only ɹeplace on this line

おすすめ記事