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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.