How to put each word in a file on a separate line

Place each word on a separate line with sed and awk:

sed -e 's/[^[:alpha:]]/ /g' | awk '{ for (i=1;i<=NF;i++) print $i }'

sed is used to replace non alpha characters with spaces (optional)

awk places each word on a separate line.

Taking it a step further you can keep only unique words with the good ol' lowercase, sort -u trick or sort|uniq if you prefer that:

awk '{ for (i=1;i<=NF;i++) print $i }' | tr "[:upper:]" "[:lower:]" | sort -u

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.