To answer the question on the title:
command that will take a file and separate each word so its on its own line
You could do:
<file tr '\n\t\r' ' '' '' ' | tr -s ' ' '\n' # needs three spaces !
It will convert newlines, tabs and carriage returns to spaces and then …
convert any run (-s
) of spaces back to one newline.
You could take advantage of the tr command and use it to also convert uppercase to lowercase in the same call:
<file tr '[:upper:]\n\t\r' '[:lower:] ' | tr -s ' ' '\n'
Or you can do exactly the same in GNU sed (mind that this will slurp the whole file into memory and assumes that no NUL bytes exist inside the file):
<file sed -zE -e 'y/A-Z\n\t\r/a-z /;s/ +/\n/g'
Then, to answer the question in the body:
(a word is defined to be a contiguous sequence of letters, so 1 letter words don't count) and to remove all blank lines.
you can remove words with characters other than a-z, one character words, and empty lines:
sed -E '/[^a-z]/d;/^.$/d;/^$/d'
It could be reduced to the slightly more cryptic:
sed -E '/[^a-z]/d;/^(.|)$/d'
All in one line, either:
<file tr '[:upper:]\n\t\r' '[:lower:] ' | tr -s ' ' '\n' | sed -E '/[^a-z]/d;/^(.|)$/d'
Or:
<file sed -zE -e 'y/A-Z\n\t\r/a-z /;s/ +/\n/g' | sed -E '/[^a-z]/d;/^(.|)$/d'
Commented version (works in GNU sed):
# Source `file` and use sed with the `zero` option (-z) and Extended Regex (ERE `-E`)
<file sed -zE -e '
# Transliterate (-y) UPPER to lower and convert control to space.
y/A-Z\n\t\r/a-z /
# Restore consecutive spaces to **one** newline.
s/ +/\n/g
# Second call to sed.
' | sed -E '
# Delete (d) lines that have nay character not in the range a-z.
/[^a-z]/d
# delete any line with one character or empty.
/^(.|)$/d
'