A command line program that implements Unix command grep like functionality.
- Python 3.9 or higher
Clone the repository:
git clone https://github.com/paramteraiya09/grep-cli-app- search string in a file
- search string from the standard input
- write output to the file
- perform case-sensitive search
- search string recursively in any of the file in a given directory
- print num lines before the match
- print num lines after the match
- print count of match
python main.py search_pattern filename [options]python main.py search_pattern -r directory_path [options]python main.py search_pattern- Replace search_pattern with the pattern you want to search for. For file-based searches, provide the filename or directory_path accordingly. Include any desired options as mentioned below.
-o, --output_file: Specify an output file to write the results.-i, --insensitive: Perform a case-insensitive search.-C, --count_only: Print only the count of matches.-A, --lines_before_match: Print N lines before the match.-B, --lines_after_match: Print N lines after the match.-r, --recursive: Search recursively in all files in the given directory.
If you prefer to run the program in a Docker container, follow these steps:
- Install Docker on your machine by following the official Docker installation guide for your operating system: https://docs.docker.com/get-docker/
- Build the Docker image using the following command:
docker build -t grep-cli-app .- Run the Docker container, mounting the input file as a volume and providing it as an argument to the Python script:
- make sure to create a txt file with some content as test.txt
docker run --rm -v "$(pwd)/test.txt:/app/test.txt" grep-cli-app test.txt [arguments]If you prefer to create a standalone executable that can be run on different operating systems without Python installed, you can use PyInstaller. Follow these steps to create an executable:
- Install PyInstaller using the following command:
pip install pyinstaller- In the terminal, navigate to the project directory that contains main.py.
pyinstaller main.py --onefile --name my_grepThe executable file will be specific to the operating system on which it was built. You'll need to repeat the build process on each target operating system to generate executables for all platforms.
python test_main.pyThis project is licensed under the MIT License. Feel free to customize the sections, commands, and examples according to your needs.