Sebastian Zeki
Sebastian Zeki

Reputation: 6874

find replace with backslashes and quotes in perl in terminal OSX

Im trying to find the line "<ablablablaLoadoftext/a>" with the double quotes being part of the text and then replace it with nothing (ie delete it)

find /MyPathToFile/AlDis.txt -type f -exec perl -p -i -e "s/\<a.*a\>\t/''/g" {} \

I suspect the error is related to how I'm handling double quotes and single quotes but I've tried backslashing them and no joy However nothing happens (but no error). Can anyone help?

Upvotes: 0

Views: 601

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

You must need to include the double quotes in regex and you don't need to add '' in the replacement part.

find /MyPathToFile/AlDis.txt -type f -exec perl -i -pe 's/"<a[^>]*\/a>"//g' {} \;

If you want to work with a single file then you don't need to use perl command inside the find command.

perl -i -pe 's/"<a[^>]*\/a>"//g' /MyPathToFile/AlDis.txt

Upvotes: 1

Related Questions