Remove the pattern with sed, which has square brackets and quotation marks

How to remove a string that has this pattern using sed

resourceNames: [""]

I tried

sed -i '/resourceNames: [""]/d' ./sa.yaml

Part of the file looks like

- apiGroups: [""]
  resources: ["secrets"]
  resourceNames: [""]
  verbs: ["get"]
---
+4
source share
2 answers

Alright.I found a problem in my code. It worked

 sed -i '/  resourceNames: [[]""[]]/d' ./sa.yaml
+2
source

Better and more reliable regex for your team sed:

sed -i '/\s*resourceNames:\s*\[""\]/d' ./sa.yaml

where you just avoid []to avoid interpreting them as a range of characters, a list of characters, and instead of space it is better to use\s*

+1
source

Source: https://habr.com/ru/post/1694635/


All Articles