Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSM - Rust String Manipulation

A human-friendly command-line text processing tool written in Rust. RSM provides intuitive alternatives to traditional Unix tools like sed, grep, and awk with a focus on usability and safety.

Features

  • Replace: Find and replace text in files (like sed)
  • Get: Search for patterns and count occurrences (like grep)
  • Print Column: Extract columns from delimited text (like awk)
  • Print Row: Display specific lines or ranges from files (like head/tail)

Security

  • Validates text files using UTF-8 encoding
  • Blocks device files and directories
  • Enforces 100 GiB file size limit
  • File locking to prevent concurrent modifications

Installation

cargo build --release

Usage

Replace

Replace text in files with case-sensitive or case-insensitive matching.

# Replace in file (modifies original)
rsm replace -f "old" -t "new" file.txt

# Case-insensitive replacement
rsm replace -f "error" -t "ERROR" file.txt -i

# Save to different file
rsm replace -f "old" -t "new" file.txt -o output.txt

# Pipe input
cat file.txt | rsm replace -f "old" -t "new"

Options:

  • -f, --from <TEXT> - Text to search for (required)
  • -t, --to <TEXT> - Replacement text (required)
  • -i, --insensitive - Case-insensitive matching
  • -o, --output <FILE> - Write to different file instead of modifying original

Get

Find lines containing a pattern or count occurrences.

# Find matching lines
rsm get "error" file.txt

# Case-insensitive search
rsm get "error" file.txt -i

# Count occurrences
rsm get "error" file.txt --count

# Pipe input
cat file.txt | rsm get "pattern"

Options:

  • -i, --insensitive - Case-insensitive matching
  • -c, --count - Show count instead of matching lines

Print Column

Extract columns from delimited text files.

# Print single column (space-delimited)
rsm print column 2 file.txt -d " "

# Print multiple columns
rsm print column 1,3 file.txt -d " "

# Print column range
rsm print column 2-4 file.txt -d " "

# CSV file with custom output delimiter
rsm print column 1,3 data.csv -d "," -o "|"

# Pipe input
cat file.txt | rsm print column 2 -d " "

Options:

  • -d, --delimiter <DELIM> - Input column delimiter (required)
  • -o, --output <DELIM> - Output column delimiter (default: space)

Note: Missing columns are displayed as [no value]

Print Row

Display specific lines, ranges, or count lines in a file.

# Count lines (skips empty lines by default)
rsm print row file.txt --count

# Count including empty lines
rsm print row file.txt --count --no-skip-empty

# First N lines
rsm print row file.txt --first 10

# Last N lines
rsm print row file.txt --last 5

# Specific line number
rsm print row file.txt --line 25

# Multiple ranges (max 5, separated by -------------)
rsm print row file.txt --range 1-5,10-15,50-55

Options:

  • -c, --count - Count total lines
  • --no-skip-empty - Include empty lines in count
  • -f, --first <N> - Print first N lines
  • -l, --last <N> - Print last N lines
  • -n, --line <N> - Print specific line number
  • -r, --range <RANGES> - Print line ranges (e.g., 1-5,10-15)

Examples

Replace all occurrences of "hello" with "hi"

rsm replace -f "hello" -t "hi" messages.txt

Find all lines containing "ERROR" (case-insensitive)

rsm get "error" logs.txt -i

Count how many times "warning" appears

rsm get "warning" logs.txt --count

Extract email column from CSV

rsm print column 3 users.csv -d ","

Print first and last name from space-delimited file

rsm print column 1,2 names.txt -d " "

Show first 20 lines of a file

rsm print row data.txt --first 20

Show specific line ranges

rsm print row file.txt --range 1-10,50-60

About

Rust String Manipulation - A human-friendly text processing tool

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages