SSR: Simple Search & Replace

HOWTO search and replace from command line

Background

I was to search and replace inside a simple batch-script and wanted a search and replace tool from the command line.
After searching I didn't find what I was looking for and compiled this simple tool.

ssr.exe (Win32-Command-Line-Tool)


Example

ssr c:\\temp\\= \\=\t test.txt
Deletes the string c:\temp\ and replaces \ (backslash) with TAB
ssr "ServerHost=Value1"="ServerHost=Value2" config_file.ini
Use above command to replace values in a config file
ssr -0 \x01=\x20 test.txt >test_space.txt
Replace hex 00 with spaces in a textfile (-0 or --zero)
ssr -m="....[05]00 {8}....[05]00.*" -h=X,Y,Z \s08=, \s07=, grid.txt -o=grid_500m.csv
Use above command to reduce huge coordinate grid file (grid in 100m) to grid in 500m CC. Grid line format: 1234567 1234567 123.45
ssr search.txt=replace.txt test.txt
Replaces the content of search.txt with the content of replace.txt in test.txt (if search.txt and replace.txt exists)
ssr -l -r "\s*([^ ])\s*\e\s*([^ ]*)\s*"="$1\e$2" test.txt
Removes whitespace around Name = Value pairs in test.txt

Download / Install

Parameters

some more parameters (compared to ssr --help) is documented here
(all parameters can be prefixed with - or -- or /)

Flags / Switches

-l or -line-by-line
use a line by line approch instead of loading content into memory. somewhat slower but allows for huge input.
-b or -binary
binary mode reads the entire input file as a raw byte stream, applies search/replace patterns, and writes the result back to a file, see binary mode below
-c or -case-sensitive
default all searches is not case sensitive
-r or -regexp
use a simple regular expression engine for search=replace, "Perl5 like regular expression", see below for explaination
-w or -write
overwrite input file
-uf or -use-file
fetch search,replace,prefix,suffix,header,footer from file (if exist) instead of command line as search.txt=replace.txt (must be placed before a search=replace pair) and can be turned on and off
-uf search.txt=replace.txt -uf -prefix=no-file-tested.txt -uf -suffix=file-content-tested.txt
-rd or -remove-duplicates
remove duplicate lines from input (before search=replace) - content is sorted (-sort flag is turned on)
-sort or -sorted
content rows is sorted (before search=replace)
-ff or -fastfind
only search (no replace) and exit with ERRORLEVEL 2 if found and ERRORLEVEL 1 if not
-unix or -unixformat
default CRLF(#13#10) is used as line endings - with this flag use LF(#10)
-h2t or -html2text or -htm2txt
simple html to text extraction/conversion
-quote or -quotes or -qoute or -qoutes
add prefix " and suffix " for each line
-ssi
"server-side-includes" expands <!--#include virtual|file="head.inc" --> and <!-- include: head.inc --> content
-mysql or -mariadb
escape some chars - "=\", CRLF=\n, CR=\n, LF=\n, TAB=\t
-json
try to extract json structures {..} [..] from content - escape ", remove tab and newline
-jsonarray
add comma between rows - for example if you have output {..} json structures into rows
-latin1 or -utf8-latin1
convert utf8 content to latin1 (conversion after search/replace)
-dos or -latin1-dos
convert latin1 content to an old dos codepage (conversion after search/replace) both -latin1 and -dos is possible

name=value

-o=filename or -output=filename
send output to file instead of standard output
-n=num or -number-of-lines=num
return first number of lines num is a number greater than 0 (turns on line-by-line)
-m=regexp or -match=regexp
only return rows matching regexp (turns on line-by-line)
-k=num or -occurrance=num
only replace first num matches (not together with line-by-line)
-h=header or -header=header
a header is prepended to the output - use -uf -header=header.txt to supply content from file (add after search/replace)
-f=footer or -footer=footer
a footer is appended to the output - use -uf -footer=footer.txt to supply content from file (add after search/replace)
-p=prefix or -prefix=prefix
a prefix to all rows - use -uf -prefix=prefix.txt to supply content from file (add after search/replace)
-s=suffix or -suffix=suffix
a suffix to all rows - use -uf -suffix=suffix.txt to supply content from file (add after search/replace)

SSR binary mode -b / -binary (from ver 1.40)

Binary mode reads the entire input file as a raw byte stream, applies search/replace patterns, and writes the result back to a file. Unlike the default text mode it does not interpret line endings, encoding, or structure - every byte is passed through as-is unless explicitly matched by a pattern.
Note: The whole file is loaded into memory at once. Not suitable for files larger than available RAM.

Basic usage

ssr -b -w \x00\x01=\xFF\xFE file.bin
Replace two bytes with two other bytes, overwrite in place
ssr -b -o patched.bin \xDE\xAD=\xBE\xEF input.bin
Write result to a new file
ssr -b -c -k=1 -w OldString=NewString firmware.bin
Case-sensitive search, replace only first occurrence
ssr -b -ff \x89PNG image.dat
Fastfind: exit ERRORLEVEL 2 if magic bytes present, 1 if not

Escape sequences in patterns

All standard \x escapes apply - uppercase hex digits only:
\x00=null(0x00), \xFF=0xFF, \n=LF(0x0A), \r=CR(0x0D), \t=TAB(0x09), \\=literal backslash

Supported options in binary mode

-c or -case-sensitive
Case-sensitive pattern matching (default: off)
-k=N or -occurrence
Replace only the first N occurrences
-ff or -fastfind
Search only - exit ERRORLEVEL 2 if found, 1 if not. No output written.
-w or -write
Overwrite the input file with the result
-o=file or -out
Write result to a separate output file
-h=bytes or -header
Prepend raw bytes to the output
-f=bytes or -footer
Append raw bytes to the output
-q or -quiet
Suppress header output to stderr

Not supported in binary mode

-r|-regexp, -l|-line-by-line, -m|-match, -n|-number-of-lines, -sh|-skip-head, -sort|-rd, -filter, -ssi, -json|-mysql, -jsonarray, -latin1,-dos,-unix. -0|-zero
No output to stdout - binary mode always writes to a file (-o or -w required)

Interaction with -w when no -o is set

If -b is used without -o or -w, ssr treats it as an implicit -w and overwrites the input file. A warning is printed to stderr.
Always specify -o explicitly if you want to keep the original.

Prefix and footer in binary mode

-h and -f write their bytes directly at the start and end of the output stream - they are not treated as text lines and no newline is added automatically.
Use \r\n or \x0D\x0A explicitly if a line break is needed.

Regexp flavor used explained

Close to Perl 5 regular expressions. Supported features (Perl-like):
  • Standard quantifiers: *, +, ?, {m,n}
  • Non-greedy quantifiers: *?, +?, ??, {m,n}?
  • Modifiers via (?ismxg-ismxg) and global Modifier* properties:
    • i - case-insensitive
    • s - dot matches newline (. = any char)
    • m - multiline (^/$ match start/end of lines)
    • x - extended syntax (whitespace + # comments)
    • g - greedy mode toggle
  • Backreferences \1-\9 (and \10+ via ${10})
  • \d, \D, \w, \W, \s, \S
  • Word boundaries \b, \B
  • \A, \Z (start/end of string)
  • Character classes [...], [^...]
  • (?#comment) and (?modifiers)
  • ^ / $ with multiline support
  • Substitution with $1, $&, ${1}, etc.
Notable absences from modern Perl/PCRE:
  • No lookaheads/lookbehinds ((?=...), (?<=...))
  • No atomic grouping (?>...)
  • No possessive quantifiers (*+, ++, etc.)
  • No recursion, conditionals, or most advanced constructs
  • Limited Unicode support (optional WideString mode, but not full Unicode properties)

Published

This tool is published in the softpedia catalogue: softpedia.com/get/System/File-Management/SSR-Simple-Search-Replace.shtml

More info

More info/questions from: Subject: SSR

Versions / History

2026-jun-11, version 1.40
-binary mode corrected and documented
2025-jun-12, version 1.38
-fixed some inconsistent params and documented params above
2025-jun-10, version 1.37
-sort and remove-duplicates fix
2022-jan-24, version 1.32
-latin1 flag: convert utf8 to latin1
2020-sep-04, version 1.3
-filter flag: return only rows matching filter string
2019-dec-16, version 1.28
new --mysql flag: escape ", tab and newline
2018-okt-12, version 1.24
new -uf (--use-file) flag, previous version always tried to find a file with content of search or replace
2017-dec-30, version 1.23
documented -rd and -sort flag
2017-dec-05, version 1.22
-k flag didn't work correct and description was updated
2017-feb-20, version 1.20
if search (or replace) is a filname, that content is not escaped by \t etc.
2016-jun-30, version 1.19
fix to use $search$replace$ pairs for shells that do not like the equal sign
2014-nov-01, version 1.17
small bug-fix
2013-sep-03, version 1.15
support for \q as " (quote)
2013-maj-31, version 1.13
added support to replace hex00 in textfiles
2013, version 1.11
Some buggfixes published
2010-mar-05, version 1.6
Support for regular expresion substitutions
2010-feb-22, version 1.5
Support for large search and replace statements
2009-nov-05, version 1.4
Buggfix, parsing correct filename from commandline
2009-oct-21, version 1.3
Line-By-Line function for huge files.
2009-aug-03, version 1.0
Implemented
Keywords: ssr,search,replace,simple,tool,command,line,cmdline,windows,text,textfile