Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I include these characters: { } [ ] " ' \ in sed 's/[^0-9A-Za-z ]*//g'?

How can I include these characters: { } [ ] " ' \ in
sed 's/[^0-9A-Za-z ]*//g' ?

From my understanding sed 's/[^0-9A-Za-z ]*//g' prints only numbers & letters and ignores everything else. Now I also want to print above symbols along with letters & numbers. So how can I do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can just add them to the regex. Note the quoting.

sed 's/[^]{}\\'\''"0-9A-Za-z[]*//g'
#        ^                          - has to be first
#                           ^       - has to be last
#           ^^                      - need to escape backslash with a backslash for sed
#             ^^^^                  - close single quotes, add single quote in shell, restart single quotes
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading