Home > Back-end >  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'?

Time:02-12

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?

CodePudding user response:

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
  • Related