0

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 :)

UPDATE:

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

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

a7Cd

Why?

1
  • 2
    Your CGI script sctually outputs a%7Cd. Maybe you should post a separate question if you need help with that. Commented Aug 13, 2013 at 14:29

1 Answer 1

1
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.

1
  • what is LC_ALL? + whoops, great.. "|" will be needed too.. Commented Aug 13, 2013 at 9:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.