ffind
Text search and replace (back in DataReel 7.4, from 6.x).
Contents
Usage
ffind [switches] file... -f"text" the first match on each line, with its line number -F"text" count every match -R"text" -W"new" replace every occurrence -i case-insensitive -L"text" -W"new" replace the rest of the line after the text -I"text" -W"new" insert after the text -c print the file -a no backslash line joining --infile=FILE (the -W text from a file) --ReplaceSection=FILE (replace that multi-line text) --ReplaceOnce --SurroundBy=Quotes|SingleQuotes|TEXT --TerminateWith=TEXT --TrimLeading=CHARS --TrimTrailing=CHARS --NoEscapeSeq
\n, \r, \t and %20 in the strings are converted unless --NoEscapeSeq. The exit code is the number of matches, replacements or insertions (at most 255), as in 6.x. A file that changes is written through a temporary file and a rename. Names with * and ? are expanded by ffind itself, so wildcards work on Windows too. Lines ending in a backslash are joined before the search (-a turns that off).
Examples
A configuration file, app.conf:
host = db1.example.com port = 5000 # backup host = db2.example.com log = /var/log/app.log
Find a string (the exit code is the number of matches, here 2), count it, or find it whatever its case:
$ ffind -f"host" app.conf File name: app.conf String: host Found match on line: #1 File name: app.conf String: host Found match on line: #3 $ ffind -F"host" app.conf File name: app.conf String: host Found 2 matches $ ffind -i -f"PORT" app.conf File name: app.conf String: PORT Found match on line: #2
Replace a string, then the rest of a line after a string. The file is changed in place:
$ ffind -R"db1.example.com" -W"db3.example.com" app.conf Opening file: app.conf Replacing: db1.example.com With: db3.example.com Replaced 1 occurrence(s). $ ffind -L"port = " -W"5001" app.conf Opening file: app.conf Replacing line after: port = With: 5001 Replaced 1 occurrence(s). $ cat app.conf host = db3.example.com port = 5001 # backup host = db2.example.com log = /var/log/app.log
Several files: quote the wildcard so ffind expands it (the same on Windows):
$ ffind -f"host" "app*.conf"