You can use grep and some regular expression for that. That's if you want to make it into one single command. If you're allowed to bash script, then that's should be fairly straightforward.
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Pipe the result through "grep", and use a regular expression that says "four characters, optionally followed by more." I'm assuming this is a school assignment, so I'm not going to actually type the command for you, but hopefully this is enough.