I'm trying to create a dictionary of words from a collection of files. Is there a simple way to print all the words in a file, one per line?
To extract the contents of the file, right-click on the file and select “Extract All” from the popup menu. On the “Select a Destination and Extract Files” dialog box, the path where the content of the .
You could use grep
:
-E '\w+'
searches for words-o
only prints the portion of the line that matches% cat temp Some examples use "The quick brown fox jumped over the lazy dog," rather than "Lorem ipsum dolor sit amet, consectetur adipiscing elit" for example text. # if you don't care whether words repeat % grep -o -E '\w+' temp Some examples use The quick brown fox jumped over the lazy dog rather than Lorem ipsum dolor sit amet consectetur adipiscing elit for example text
If you want to only print each word once, disregarding case, you can use sort
-u
only prints each word once-f
tells sort
to ignore case when comparing words# if you only want each word once % grep -o -E '\w+' temp | sort -u -f adipiscing amet brown consectetur dog dolor elit example examples for fox ipsum jumped lazy Lorem over quick rather sit Some text than The use
A good start is to simply use sed
to replace all spaces with newlines, strip out the empty lines (again with sed
), then sort
with the -u
(uniquify) flag to remove duplicates, as in this example:
$ echo "the quick brown dog and fox jumped
over the lazy dog" | sed 's/ /\n/g' | sed '/^$/d' | sort -u
and
brown
dog
fox
jumped
lazy
over
quick
the
Then you can start worrying about punctuation and the likes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With