How to filter Alphanumerics

Hi all,

Can you please let me know how to achieve the below thing

AAABBCC@#$W123
123@#$DFG<>.

Output:
AAABBCW123
123DFG

i.e I want to filer only alphanumerics from the strings

sed -e 's/[^A-Za-z0-9]//g' file

thanks !

sed -e 's/[:alnum:]//g' 

should also work I guess..

tr -cd '[:alnum:]\n'

---------- Post updated at 12:41 AM ---------- Previous update was at 12:39 AM ----------

It won't. What you're going for is:

sed -e 's/[^[:alnum:]]//g'

Regards,
Alister