Reggie Kapros Reggie Kapros - 10 months ago 49
Linux Question

How to print words that contain only letters?

If I'm given a file how can I print the words that contain only the characters A-Za-z (so only letters) in alphabetical order? Should I use awk?Could someone help me with suggestions/example?

So if I have the file file1.txt
and it looks like this:

ahk4 ble ach cop v59l k9l
h6j alo

The ouptut will look like this:
ach alo ble cop


To get the words contain alphabet only:

$ tr -cs '[:alnum:]' '[\n*]' <file | grep -E '^[[:alpha:]]+$'

To get your desired output:

$ tr -cs '[:alnum:]' '[\n*]' <file |
  grep -E '^[[:alpha:]]+$'         | 
  sort                             |
  paste -sd ' ' -