A minimal version of 'grep' implemented in Rust. Exercise in the "The Rust Programming Language" book.

Overview

Minigrep - A simple grep-like tool implemented in Rust

This simple CLI tool searches for a given pattern in a specified file and as a result, it prints all the lines that contain the pattern.

This program is a simple implementation of the grep command-line tool in Rust. It is an exercise present in the Rust Programming Language book. It includes an extra feature of searching for a pattern in multiple files, which is not present in the original exercise. This feature was added to practice mutli-threading in Rust.

Working through the exercise, the developer gets introduced to handling command-line arguments, reading files, error handling, and other concepts in Rust.

Usage

The requirement for running/building this program is having the Rust Programming language instaled. Learn how to get started on the official website.

After cloning this repository, navigate to the project's root directory and run the following command:

$ cargo run <pattern> <file path | multiple paths>

Where <pattern> is the pattern you want to search for and <file> is a file path for the file you want to search the contents of.

Example

Single input

$ cargo run to _poem.txt

Are you nobody, too?
How dreary to be somebody!

Multiple inputs

$ cargo run to _poem.txt _funny.txt _serious.txt

[_poem.txt]:
Are you nobody, too?
How dreary to be somebody!

[_funny.txt]:
Lived a man with too many felines.
Remember this whimsical town.

[_serious.txt]:
A journey embarked, yet often untold.
Echoing stories only time can tell.
Love's gentle touch, a soothing balm,

Case insensitive search

To perform a case-insensitive search, set the IGNORE_CASE environment variable to any value.

$ IGNORE_CASE=1 cargo run to _poem.txt

Are you nobody, too?
How dreary to be somebody!
To tell your name the livelong day
To an admiring bog!
You might also like...
Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.
Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.

Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.

High Assurance Rust - A free book about developing secure and robust systems software.

High Assurance Rust - A free book about developing secure and robust systems software.

Learn programming with Rust as a first language (book)

Learn programming with Rust as first language This is a book to learn programming from scratch. Read the book here: https://deavid.github.io/lprfl/ LI

Search and read 'The Rust Book' from the terminal
Search and read 'The Rust Book' from the terminal

TheBook TheBook is a command line utility that allows you to SEARCH and READ The Rust Programming Language (popularly known as 'The Book' ) from the t

Book - Actix user guides

User guides Actix User Guide Actix API Documentation (Development) Actix API Documentation (Releases) Actix Web User Guide Actix Web API Documentation

Complete code for the larger example programs from the book.

Code Examples for Programming Rust This repository contains complete code for the larger example programs from the book “Programming Rust”, by Jim Bla

Majestic Lisp book and implementation, in Brazillian Portuguese.

Majestic Lisp Criado e desenvolvido por Lucas S. Vieira lucasvieira at protonmail dot com. Seja bem-vindo(a) a Majestic Lisp, um dialeto de Lisp cuj

Generate SUMMARY.md files based on your book's file structure

mdbook-autosummary Generate a SUMMARY.md for your mdBook based on your folder structure! Warning The implementation is hacky and has several limitatio

The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language.

rcc The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language. Compilers Language Co

Owner
Filip Szutkowski
Front-end Web Developer
Filip Szutkowski
A short exercise to introduce people to the Rust programming language

Searching primes by brute force This code is ment to be an exercice to teach rust and give a first impression on how to work with the language during

JoelImgu 3 Dec 14, 2022
The Rust Programming Language, Chapter 8, Exercise 1

Rust Common Collections - Exercise 1 In the book The Rust Programming Language by Steve Klabnik and Carol Nichols, chapter 8 - Common Collections - pr

David Jones 0 Dec 24, 2021
This repository contains the source of "The Rust Programming Language" book.

The Rust Programming Language This repository contains the source of "The Rust Programming Language" book. The book is available in dead-tree form fro

The Rust Programming Language 11.2k Jan 8, 2023
Voluntarily contributed solutions for the first practical exercise for the Compilerbau lecture WiSe 2021/2022 of Ulm University

Solutions for the first practical exercise Compilerbau lecture WiSe 2021/2022 - Ulm University Contributing Want to add your solution? Great! Just add

null 5 Dec 4, 2021
A refactoring kata, made to exercise learnings from Chapter 6 of Refactoring by Martin Fowler

Fighter Dude 2 - Refactoring Kata This is a tiny refactoring kata that I made to exercise some of the refactorings in Chapter 6 of Refactoring by Mart

Declan Hopkins 3 Dec 17, 2021
A repository for showcasing my knowledge of the Rust programming language, and continuing to learn the language.

Learning Rust I started learning the Rust programming language before using GitHub, but increased its usage afterwards. I have found it to be a fast a

Sean P. Myrick V19.1.7.2 2 Nov 8, 2022
A library for extracting #[no_mangle] pub extern "C" functions (https://docs.rust-embedded.org/book/interoperability/rust-with-c.html#no_mangle)

A library for extracting #[no_mangle] pub extern "C" functions In order to expose a function with C binary interface for interoperability with other p

Dmitrii - Demenev 0 Feb 17, 2022
The ray tracer challenge in rust - Repository to follow my development of "The Raytracer Challenge" book by Jamis Buck in the language Rust

The Ray Tracer Challenge This repository contains all the code written, while step by implementing Ray Tracer, based on the book "The Ray Tracer Chall

Jakob Westhoff 54 Dec 25, 2022
Source code for the book Rust in Action

Welcome to Rust in Action source code This source code repository is a companion to the Rust in Action book available from Manning Publications. Suppo

Rust in Action 1.3k Dec 30, 2022
Code to follow along the "Zero To Production" book on API development in Rust.

Zero To Production / Code (Chapter 10 - Part 1) Zero To Production In Rust is an opinionated introduction to backend development using Rust. This repo

Luca Palmieri 2.8k Dec 31, 2022