Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Replace, brackets

Status
Not open for further replies.

serathigeos

Programmer
Apr 18, 2006
2
JP
I want to replace every occurance of "[0:12:#abc():34]" with
"#abc(34)", but the following is not doing the trick:
perl -pi~ -e 's/[0:12:#abc():34]/#abc(34)/g' file.txt

How can I replace literal brackets? []
-Brendan
 
YOu need to escape certtain characters, typically []()/\ and . You might also have problems with the #.
So try
Code:
perl -pi~ -e 's/\[0:12:\#abc\(\):34\]/\#abc\(34\)/g' file.tx

Columb Healy
 
just use Q\...\E:

Code:
perl -pi~ -e 's/\Q[0:12:#abc():34]\E/\#abc(34)/g' file.tx

Q\...E\ automatically escapes the meta characters in a regexp to avoid interpolation of their special meaning. You would need to escape the [] and () otherwise because they have special meaning in a regexp as Columb noted.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top