gsar (General Search and Replace)
Try It End of life
Utility for searching for and optionally replacing strings in both text and binary files. The search and replace strings can contain all kinds of characters (0--255), i.e. CTRL characters and extended ASCII as well.
Gsar can search one or several files for a string and report the occurrences. Gsar can read one file, search for a string, replace it with some other string, and create a new file containing the changes. Gsar can perform a search and replace in multiple files, overwriting the originals. Finally, gsar can work as a filter, reading from standard input and writing to standard output.
Notes
No mutli-line or regex support. (All files and strings are treated as binary.) The algorithm used is a variation of the Boyer-Moore search algorithm, modified to search binary files. As a result of this, gsar is blindingly fast.
Version
Latest known: 1.21 (2008-01-30)
Examples
1. Replace all instances of case-insensitive "cold fusion" with "ColdFusion".
Rename a JSON key with literal byte search/replace
Use gsar's literal-byte search and replace to rename the JSON key 'balance' to 'accountBalance' in users.json. The search pattern is anchored as the quoted form '"balance":' so a value happening to contain the word 'balance' would not be touched. gsar writes the modified bytes to a temp file (passed as the second positional arg, with -f to force overwrite) and the demo reads that file back into the Output panel as pretty-printed JSON. The Result panel shows the rename details plus gsar's own 'Changed N occurrences' summary line. Because gsar operates on raw bytes, it is much faster than a JSON parse-modify-serialize round trip and is safe across encodings.
# gsar (General Search and Replace) - Help
Source: https://gnuwin32.sourceforge.net/packages/gsar.htm
```
gsar, ver 1.21 -- Copyright (C) 1992-2008 Tormod Tjaberg & Hans Peter Verne
Usage: gsar [options] [infile(s)] [outfile]
Options are:
-s<string> Search string
-r[string] Replace string. Use '-r' to delete the search string from the file
-i Ignore case difference when comparing strings
-B just display search & replace Buffers
-f Force overwrite of an existing output file
-o Overwrite the existing input file
-c[n] show textual Context of match, 'n' is number of bytes in context
-x[n] show context as a heX dump, 'n' is number of bytes in context
-b display Byte offsets of matches in file
-l only List filespec and number of matches (default)
-h suppress display of filespec when displaying context or offsets
-du convert a DOS ASCII file to UNIX (strips carriage return)
-ud convert a UNIX ASCII file to DOS (adds carriage return)
-F 'Filter' mode, input from stdin and eventual output to stdout
-G display the GNU General Public Licence
Ctrl characters may be entered by using a ':' in the string followed by the
ASCII value of the character. The value is entered using ':' followed by three
decimal digits or ':x' followed by two hex numbers. To enter ':' use '::'
```