Amardeep reddy
Amardeep reddy

Reputation: 127

perl program to replace a string in a file multiple times

I would like to replace "int" with "int int int" in a file practice.py. The below code is not working.

perl -p -i -e "s/int/int{3}/g" practice.py; 

Upvotes: 1

Views: 89

Answers (2)

mpapec
mpapec

Reputation: 50637

perl -i -pe 's/(int)\K/ $1 $1/g' practice.py

(-pe ".." if using windows)

Upvotes: 2

b4hand
b4hand

Reputation: 9770

perl -p -i -e "s/int/int int int/g" practice.py;

The {3} can only be used to match in a regex not in a substitution.

Upvotes: 1

Related Questions