A collection of Python command-line tools for analyzing and searching text files inside a local directory.
- Select a text file from a menu
- Count lines, words, and non-whitespace characters
- Generate a word-frequency dictionary
- Display the top 5 most frequent words
- Search for a word in a selected file
- Perform case-insensitive matching
- Count total occurrences
- Count matching lines
- Print matching lines to the terminal
- Create a new text file containing the matching lines
textfiles-reader/
├── sample-textfiles/
├── analyze_text.py
├── search_extract.py
├── README.md
└── .gitignore
- Python 3
- Standard library:
stringtime
- File handling with
open() - Reading and writing text files
- Exception handling
- Dictionaries and frequency counting
- String processing
- Removing punctuation with
translate() - Case-insensitive searching
- Building command-line interfaces
Pick a number: 2
→ You selected Clown.txt
This dictionary has 11 key-value pairs.
Total words in this file are 24
Total lines in this file are 1
Total non-whitespace characters in this file are 82
Top 5 most frequent words are:
the — 7 times
car — 3 times
and — 3 times
tent — 2 times
ran — 2 times
Enter file name (with ".txt" extension): clown.txt
What word do you want to look for in clown.txt: the
There is 1 line that contains the word "the".
Total word count: 7
Completed ✔