CC-Grep is a custom command-line grep utility developed as part of a coding challenge. It supports case-insensitive searches, recursive file matching, and inverted matches to display lines that do not contain the specified pattern.
Challenge URL: https://codingchallenges.fyi/challenges/challenge-grep
- Case-Insensitive Search: Use the
-i
flag to perform case-insensitive pattern matching. - Recursive Search: Use the
-r
flag to search through all files within a directory and its subdirectories. - Inverted Match: Use the
-v
flag to return lines that do not contain the specified pattern. - Command-line Interface (CLI): Simple and efficient CLI for flexible text searching.
These instructions will help you set up and use cc-grep
on your local machine.
- Go: Ensure that Go (version 1.15 or later) is installed on your system. You can download it from https://golang.org/dl/.
Clone the repository to your local machine:
git clone https://github.com/nullsploit01/cc-grep.git
cd cc-grep
To compile the project, run:
go build -o ccgrep
Run tests to verify the application’s functionality:
go test ./...
To use the utility, execute the compiled binary with the desired options:
Search for a pattern in a file:
./ccgrep "Rock" test_data/rockbands.txt
- Case-Insensitive Search: Use -i or --case-insensitive to ignore case.
- Recursive Search: Use -r or --recursive to search through all files in a directory and its subdirectories.
- Inverted Match: Use -v or --invert to return lines that do not contain the specified pattern.
Perform a case-insensitive search for “symbol” in symbols.txt:
./ccgrep -i "symbol" test_data/symbols.txt
Search recursively for the word “1985” in all files within the test_data directory and its subdirectories:
./ccgrep -r "1985" test_data
Find all lines in test.txt that do not contain the word “example”:
./ccgrep -v "example" test_data/test.txt
Perform a recursive, case-insensitive search for “band” in all files within test_data, returning only lines that do not contain the pattern:
./ccgrep -r -i -v "band" test_data