I'm trying to find some text in an XML file and delete only a part of a line that has it. I found this format to try: perl -p -i -e 's/$1/$2/g' $3 after some code searches.
So I'm using this code:
In Perl One-Liners, author and impatient hacker Peteris Krumins takes you through more than 100 compelling one-liners that do all sorts of handy things, such as manipulate line spacing, tally column values in a table, and get a list of users on a system. This cookbook of useful, customizable, and fun scripts will even help hone your Perl coding.
What I want to do is delete everything from the inner single quotes as in:'../../../specialText/', but using q() or ' to escape the quote doesn't work and I'm not sure the ..'s aren't messing things up either. I'm guessing that not putting anything in as a text replacement will delete it properly, but I'm not sure.
The errors are:
Backslash found where operator expected at -e line 1, near '/specialText/'
(Missing operator before ?)syntax error at -e line 1, near '/specialText/'
Can't find string terminator '' anywhere before EOF at -e line 1.
How do rewrite this one liner to accomplish this?
This works.
I tried it on another file, so now I just have to play with it to modify my original.
James Drinkard
James DrinkardJames Drinkard
2 Answers
And what's wrong with using another set of delimiters?
raina77owraina77ow
You can escape the . and / characters in the search string by putting a backslash () before each of them.
However, to avoid acute leaning toothpick syndrome, I'd recommend instead using alternative regexp delimiters and the Q and Eescape sequences, like this:
Ilmari KaronenIlmari Karonen
Not the answer you're looking for? Browse other questions tagged perl or ask your own question.