Skip to content

errorgenerator/quickreplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quickreplace - a CLI tool written in Rust

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

Building and running:

CLICK TO EXPAND

Requirements:

  • rustup - with any toolchain installed.
    • rustc and cargo required.

Building:

  1. clone this repo
git clone https://github.com/errorgenerator/quickreplace.git
  1. change into the directory
cd ./quickreplace 
  1. build the code with cargo
cargo build --release
  1. the compiled binary can be found in the newly created target/release directory.
cd ./target/release
  1. you can now run the binary with ./quickreplace

USAGE:

Usage: quickreplace <target> <replacement> <INPUT> <OUTPUT>

quickreplace expects 4 Arguments:

  1. target - the String to search for.
  2. replacement - the String to replace target with
  3. INPUT - the path to a file containing the contents to filter.
  4. OUTPUT - the path to a file to write the filtered contents to.

Examples:

  • Replace every occurence of "World" in Hello.txt with "Rust" and write the output to Hello_Copy.txt:

quickreplace "World" "Rust" ./Hello.txt ./Hello_Copy.txt

  • Replace every occurence of "F" in Grades.csv with "A" and write the filtered contents back into Grades.csv:

quickreplace "F" "A" ./Grades.csv ./Grades.csv

About

A small quickreplace example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages