How can I remove numbers within brackets only? For example, I have the following text:
This is 14 April [988] text..
I would like to remove the [988]
and leave 14
intact.
What i've tried so far:
sed 's@\[[0-9]\]@@g'
How can I remove numbers within brackets only? For example, I have the following text:
This is 14 April [988] text..
I would like to remove the [988]
and leave 14
intact.
What i've tried so far:
sed 's@\[[0-9]\]@@g'
You can use:
On Mac:
sed -E 's@\[[0-9]+\]@@g'
On Linux:
sed -r 's@\[[0-9]+\]@@g'
You need to enable repeating (multiple) numerical characters in order to get this work - as it stands, your regex will remove only single-digit numbers. If you want numbers composed of at least one (one or more) numerical characters, try
sed -E 's/\[[0-9]+\]//g'
This should work (added the escaped +
)
sed 's@\[[0-9]\+\]@@g'