regular expression in sed replace question mark

Dozel

I would like to replace all non-printable char and space and question mark to nothing.

sed 's/[^[:print:]\|?\| \r\t]//g'

but this will only replace non-printable char. The space and the question mark remains.

Wiktor Stribiżew

A pipe in the bracket expression means a pipe, not an alternation operator.

You can use

sed -E 's/[^[:print:]]|[[:blank:]?]//g' file > outfile

Here,

  • -E enables the POSIX ERE syntax
  • [^[:print:]] - any non-printable char
  • | - or (here, due to -E and the fact it is outside a bracket expression, it is an alternation operator [[:blank:]?] - a horizontal whitesapce or question mark.

You may chain two commands if you want to use POSIX BRE:

sed 's/[^[:print:]]//g;s/[[:blank:]?]//g' file > outfile

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related