how to replace a String inside a File using perl ?
perl -pi -e 's/Arun/Brun/g' *
this worked fine for me
but when i tried to change class/students/a to class1/students1/B it throws error how to solve this problem ..i tried adding back slash (\) before every (/) but it didn’t help
perl -pi -e 's/class/students/a/class1/students1/B/g' *
You are using
/as regex delimiter.There are
/even in your pattern and replacement. You need to somehow ensure that these/should not be treated as delimiter.You have two options:
Escape the
/in your pattern and replacement as:Or use a different delimiter:
Method 2 is preferred as it keeps your regex short and clean.