Perl - Insert lines after a match is found in a file

前端 未结 5 1692
南笙
南笙 2021-01-24 09:34

I have a file with the following syntax in some_1.xyz

module some_1 {
INPUT PINS
OUTPUT PINS
}

and I want to insert APPLY DELAYS xx and APPLY L

5条回答
  •  旧巷少年郎
    2021-01-24 10:09

    $text='bla bla mytext bla bla';
    $find='.*mytext.*';
    $repl='replacement';
    
    $text=~ s/($find)/$1$repl/g;
    

    $1 is basically your match and you can use it when you make the replacement, either before or after your $repl string. )))

    EASY

提交回复
热议问题