How can I "whitelist"/output only the (ENglish) a-z;A-Z;0-9;| chars and space in ksh/OpenBSD 5.3?

$ echo 'ASDF"`date`ew � kd A | A'
ASDF"`date`ew � kd A | A
$ echo 'ASDF"`date`ew � kd A | A' | MAGIC
ASDFdateew  kd A | A

So Q: MAGIC is needed :)


echo 'a|d' | LC_ALL=EN tr -dc '[:alnum:][:space:]|'

This works in console, but If I put it in a CGI script then it outputs this:



  • 2
    Your CGI script sctually outputs a%7Cd. Maybe you should post a separate question if you need help with that. – tripleee Aug 13 '13 at 14:29
echo 'áé{D`AS' | LC_ALL=C tr -cd '[:alnum:]|'

(note that it will also remove the newline character appended by echo).

LC_ALL fixes the locale which determines what characters are and which of them are considered letters or numbers. In the C locales, characters are single-bytes and alnums are the ASCII characters A to Z, a to z and 0 to 9.

  • what is LC_ALL? + whoops, great.. "|" will be needed too.. – gasko peter Aug 13 '13 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.