help filefilter
-------------------------------------------------------------------------------
Title
[D] filefilter -- Convert ASCII text or binary patterns in a file
Syntax
filefilter oldfile newfile , from(oldpattern) to(newpattern)
[options]
where oldpattern and newpattern for ASCII characters are
"string" or string
string := [char[char[char[...]]]]
char := regchar | code
regchar := ASCII 32-91, 93-128, 161-255; excludes '\'
code := \BS backslash
\r carriage return
\n newline
\t tab
\M Mac EOL, or \r
\W Windows EOL, or \r\n
\U Unix EOL, or \n
\LQ left single quote, `
\RQ right single quote, '
\Q double quote, "
\$ dollar sign, $
\###d 3-digit [0-9] decimal ASCII
\##h 2-digit [0-9,A-F] hexadecimal ASCII
options description
-------------------------------------------------------------------------
* from(oldpattern) find oldpattern to be replaced
* to(newpattern) use newpattern to replace occurrences of from()
replace replace newfile if it already exists
-------------------------------------------------------------------------
* from(oldpattern) and to(newpattern) are required.
Description
filefilter reads an ASCII input file, searching for oldpattern. Whenever
a matching pattern is found, it is replaced with newpattern. All
resulting data, whether matching or nonmatching, are then written to the
new ASCII file.
Because of the buffering design of filefilter, arbitrarily large files
can be converted quickly. filefilter is also useful when traditional
editors cannot edit a file, such as when unprintable ASCII characters are
involved. In fact, converting end-of-line characters between Mac,
Windows, and Unix is convenient with the EOL codes.
Unicode is not directly supported at this time, but you can attempt to
operate on a Unicode system by breaking a 2-byte character into the
corresponding two-character ASCII representation. However, this goes
beyond the original design of the command and is technically unsupported.
If you attempt to use filefilter in this manner, you might encounter
problems with variable-length encoded Unicode.
Although it is not mandatory, you may want to use quotes to delimit a
pattern, protecting the pattern from Stata's parsing routines. A pattern
that contains blanks must be in quotes.
Options
from(oldpattern) is required and specifies the pattern to be found and
replaced.
to(newpattern) is required and specifies the pattern used to replace
occurrences of from().
replace specifies that newfile be replaced if it already exists.
Examples
. filefilter macfile.txt winfile.txt, from(\M) to(\W) replace
. filefilter auto1.csv auto2.csv, from(\LQ) to("left quote")
. filefilter auto1.csv auto2.csv, from(\60h) to("left quote")
. filefilter auto1.csv auto2.csv, from(\096d) to("left quote")
. filefilter file1.txt file2.txt, from("\6BhText\100dText") to("")
Saved results
filefilter saves the following in r():
Scalars
r(occurrences) number of oldpattern found
r(bytes_from) # of bytes represented by oldpattern
r(bytes_to) # of bytes represented by newpattern
Also see
Manual: [D] filefilter
Help: [P] file, [D] changeeol, [D] hexdump