Reputation: 633
I need to get rid of the double square brackets, I only need them once. However I get the error below after this command:
sed -ri 's/("opening_hours": \[\[)(.*?)(\]\]/"opening_hours": \[\2\]/' ./foo.txt
Error: sed: -e expression #1, char 60: Unmatched ( or (
input(foo.txt):
"opening_hours": [["Pendant les expositions : le jeudi de 12h \u00e0 20h et\u00a0du vendredi au dimanche, de 12h \u00e0 18h"]]
"opening_hours": [["\u00d6ffnungszeiten: Fr-Sa, 15-7 Uhr und nach Vereinbarung", "Open hours: Fri-Sat, 3-7pm and by appointment"]]
expected output:
"opening_hours": ["Pendant les expositions : le jeudi de 12h \u00e0 20h et\u00a0du vendredi au dimanche, de 12h \u00e0 18h"]
"opening_hours": ["\u00d6ffnungszeiten: Fr-Sa, 15-7 Uhr und nach Vereinbarung", "Open hours: Fri-Sat, 3-7pm and by appointment"]
Upvotes: 3
Views: 380
Reputation: 58351
This might work for you (GNU sed):
sed -E 's/\[([^][]*)\]/\1/' file
Match a [
followed by zero or non [
and ]
followed by a ]
and replace it by the value between the [
and ]
.
N.B. The [^][]
matches not a [
or a ]
.
Upvotes: 1
Reputation: 133428
For matching the exact brackets with your shown samples I would suggest to use following. Where I am using 2 substitutions but regex is to match more accurate brackets here.
sed 's/": \[\["/": [":/; s/"\]\]$/"]/' Input_file
Upvotes: 2
Reputation: 88543
For better clarity, I suggest using two s
commands:
sed 's/\[//; s/]//' foo.txt
Upvotes: 2