delete specific character "[" from a file
Yes, the [
character is special as it starts a [...]
group (a bracketed expression).
With sed
on OpenBSD, your command gives a more helpful error message:
$ sed 's/[//g'
sed: 1: "s/[//g": unbalanced brackets ([])
To delete all [
characters using sed
, escape it:
sed -i 's/\[//g' file
Or put it inside a bracketed expression:
sed -i 's/[[]//g' file
Or, use tr
,
tr -d '[' <file >file.new
Also, don't use in-place editing with sed
until you know the expression that you are trying out actually works, or you will possibly have to restore your data from backups.