編集した文字列を含む重複行[閉じる]

編集した文字列を含む重複行[閉じる]

小さな編集文字列を含むファイルから行をコピーする方法を見つける必要があります。レプリカは元の行の上に表示する必要があります。それが最善の選択でしょうかsedawk

理想的には、新しいpuppies行に置き換えて交換することをお勧めします。bunniesIYou

たとえば、

  • 入力ファイル:
    I have puppies cute 
    I have two kitties
    I have three puppies cute
    I have four kitties
    
  • 結果は次のとおりです。
    You have bunnies cute
    I have puppies cute
    I have two kitties
    You have three bunnies cute 
    I have three puppies cute
    I have four kitties
    

ベストアンサー1

GNUの使用sed:

sed 'h; s/puppies/bunnies/g; T; s/I/You/; G' < your-file

おすすめ記事