Deleting everything between [ ] in a list

Home / Uncategorized / Deleting everything between [ ] in a list

Question:
I have a list of 500 individual lines and they consist of:12 asdfdfsdfz adf [SGH]
1 sDasd fsdfsdf [SGV]

and so on 500 times.

I wish to remove everything in between the brackets and the brackets themselves

Any help would be helpful thanks in advanced


Answer:
Use a Unix tool called sed and match them with RegEx, and now you have two problems.
sed ‘s/[[A-Z]*]//g’ your.file > output.txt

Do note that this will delete them only if there’s nothing but UPPERCASE letters between the brackets, i.e. it will not delete something like [abcd]

Strictly speaking, the above command will only delete
An opening bracket [, followed by
Zero or more uppercase letters, and followed by
A closing bracket ].
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *