Solution: Count Words and Lines in a Text File
Run the program from the command-line interface and test our implementation.
We'll cover the following...
Solution
Type ruby main.rb file.txt
in the CMD to execute the following code:
Lacus sed turpis tincidunt id aliquet risus. Scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique senectus et. Rhoncus dolor purus non enim praesent elementum. Feugiat scelerisque varius morbi enim nunc faucibus. Pellentesque habitant morbi tristique senectus. Feugiat scelerisque varius morbi enim nunc. Dictumst vestibulum rhoncus est pellentesque elit ullamcorper dignissim. Urna nunc id cursus metus. Neque volutpat ac tincidunt vitae semper quis lectus nulla. Aliquam ultrices sagittis orci a scelerisque purus semper eget duis. Ornare massa eget egestas purus viverra accumsan in nisl. Eget dolor morbi non arcu risus quis varius quam quisque. Sed adipiscing diam donec adipiscing tristique risus nec. Vulputate ut pharetra sit amet. Dignissim enim sit amet venenatis urna cursus eget nunc. Eu consequat ac felis donec. Ut placerat orci nulla pellentesque dignissim enim sit.
Counting words and lines in a text file
Explanation
Line 1: Here, the program ...