0

I'm running this perl cmd on Mac OS to delete the whole line.

perl -i -pe's/<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id"/>/ /g' AndroidManifest.xml

The result is

fb_app_id"@string/fb_app_id"/> 

I'm unable to escape the / in "@string/fb_app_id tried different variations @string//fb_app_id and @string\/fb_app_id but none worked.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Exhaler
  • 105
  • 1
  • 9

3 Answers3

3

If you had been using warnings, you would have been notified that @strings is being considered a variable and interpolated in the regex. You should try to escape the @. And also the slashes.

perl -i -pe's/<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\@string\/fb_app_id"\/>\/ /g' AndroidManifest.xml 

Running a Perl command without warnings is a bad idea, even if you are a Perl expert.

Notable things:

  • You should not parse XML with a regex. Related infamous answer.
  • You do not need to use a substitution, you can try a looser match using m// with the -n switch, and then avoid printing matching lines. E.g.
perl -i -nwe'print unless m|android:value="\@string/fb_app_id"|'
TLP
  • 66,756
  • 10
  • 92
  • 149
1

Can you try using delimiter [] ?

perl -i -pe's[<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\@string/fb_app_id"/>][ ]g' AndroidManifest.xml
Philippe
  • 20,025
  • 2
  • 23
  • 32
1

Notwithstanding the hazzards of using regex on XML, here is how you would normally do a task like this.

Use curly braces as the delimiters. s{}{}
Manually escape these characters. $ @ \ --> \$ \@ \\
If it's a fixed string, wrap it with \Q\E. Otherwise periods and other regex meta characters will cause unintended effects.

perl -i.bak -pe 's{\Q<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\@string/fb_app_id"/>\E}{ }g' AndroidManifest.xml

To merely comment out the block:

perl -i.bak -pe 's{(\Q<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\@string/fb_app_id"/>\E)}{<!-- $1 -->}g' AndroidManifest.xml

HTH

lordadmira
  • 1,807
  • 5
  • 14