quickreplace allows you to replace every occurence of a string of your choosing within a file and write the changed text to an output file
This code originates from the example found in the book:
Programming Rust - Fast, Safe Systems Development
- by Jim Blandy, Jason Orendorff and Leonora F.S. Tindall.
This particular example can be found in Chapter 2: A tour of Rust - Filesystems and Command-Line Tools
CLICK TO EXPAND
- rustup - with any toolchain installed.
- rustc and cargo required.
- clone this repo
git clone https://github.com/errorgenerator/quickreplace.git- change into the directory
cd ./quickreplace - build the code with cargo
cargo build --release- the compiled binary can be found in the newly created
target/releasedirectory.
cd ./target/release- you can now run the binary with
./quickreplace
Usage: quickreplace <target> <replacement> <INPUT> <OUTPUT>
target- the String to search for.replacement- the String to replacetargetwithINPUT- the path to a file containing the contents to filter.OUTPUT- the path to a file to write the filtered contents to.
Examples:
- Replace every occurence of "World" in
Hello.txtwith "Rust" and write the output toHello_Copy.txt:
quickreplace "World" "Rust" ./Hello.txt ./Hello_Copy.txt
- Replace every occurence of "F" in
Grades.csvwith "A" and write the filtered contents back intoGrades.csv:
quickreplace "F" "A" ./Grades.csv ./Grades.csv