|
a command line
free external tools,
java sources
cpp sources
articles
|
- download the free swiss file knife base from sourceforge. - unpack the tool using winzip or unzip. - open the Windows Command Line or a Linux shell. sfk replace singleFile [-text] /src/dst/ [pattern2] [...] [-yes] sfk rep[lace] -[s]pat -bin[ary] /A0A1A2/B5B6B7/ -dir anydir -file .ext1 [-yes] sfk hexfind [-nodump] -pat /pattern/ -dir anydir -file .ext1 [.ext2] sfk replace [-dump [-wide]] -bylist words.txt file1 [file2 ...] [-yes] search and replace text or byte blocks (specified as hex code) within text or binary files. if multiple patterns are given, then each of them is searched independently (OR combination). by default, this function runs in SIMULATION mode, previewing hits without changing anything. specify -yes to really apply the changes. multiple patterns are executed in the given sequence. Mind this if they overlap, e.g. /foo/bar/ /foosys/thesys/ makes no sense (foo is replaced by the first expression, so the 2nd one will always fail to match). replacing source / target patterns of different length is slower and may require much memory compared to replacements of same length. no wildcards are supported. if you need to replace text by wildcards within ASCII text files, use sfk filter with -replace ... -write. subdirectories are included by default! the sfk default for most commands is to process the given directories, as well as all subdirs within them. specify -nosub to disable this. options: -nosub : do not include files in subdirectories. this is default when specifying a single file name after replace. -quiet : do not print progress status and total hits statistics. -quiet=2 : also do not print the files checked / changed message. -verbose : tell more details about what is done. -case : case-sensitive text comparison. default is case-insensitive comparison for all -text strings, but NOT for -bin blocks. case-sensitive comparison is faster then case-insensitive. -nocase : force case-insensitive comparison ALSO on -bin patterns. -pat : starts a list of text replacement patterns of the form xsrcxdstx where x is the separator char, src the source to search for, and dst the destination to replace it with. e.g. /foo/bar/ or _foo_bar_ both replace foo by bar. -pat is not required if a singleFile name is given. -text : the same as -pat, starting a text replace pattern list. -spat : the same, but also activates slash patterns like \t . type "sfk help pat" for the list of possible patterns. -spats[trict] : same as -spat, but stops with error on undefined slash patterns like \m in C:\myproj. every slash must then be escaped, e.g. using C:\\myproj. -bin[ary] : starts a list of binary replace patterns, specified as hexcode like /0A0D/2020/ -dump [-lean] : create hexdump of hits, listing 8 bytes per line. also previews changes on replacements of same length. -dump -wide : create hexdump of hits, listing 16 bytes per line; requires a shell window with at least 120 columns. -nodump : hexfind dumps by default. specify -nodump to disable. -reldist : for each hit, tell relative distance to previous hit. -context=n : with -dump, show additional n bytes of context. -bylist x.txt : read replacement patterns from a file (see below). -memlimit=nm : with different-length replacements, files must be loaded into memory for processing. the default limit for memory use is 300 MB. set -memlimit=500m to select 500 MB. -enddir : to use -dir ... -file ... as first parameters, type: sfk rep -dir ... -file ... -enddir myfile.dat -pat ... -firsthit : process only first found pattern match per file. Run a simulation first, to see what would be changed. Changing binaries may lead to unpredictable results, therefore keep backups in any case. return codes for batch files 0 = no matches, 1 = matches found, >1 = major error occurred. see also "sfk help opt" on how to influence error processing. see also sfk filter mytext.txt -replace _from_to_ -write sfk select mydir .txt +ffilter -replace _from_to_ -write flexible, line based text processing which also supports the * and ? wildcards. type sfk filter for more. sfk view a high speed GUI text file search tool. searches words as you type, or by clicking on them, instantly. SFK XE High Performance Replace SFK XE contains a different replace implementation, allowing high speed different-length replacements even in gigabyte-large files, optional file-to-file replace, and optional usage of temporary files if output does not fit into memory. "sfk help xe" for more. the -bylist pattern command file may contain ":text" or ":binary" commands followed by any number of replacement patterns, and remark lines starting with ":#" if the first line is no command, a ":text" section is assumed. specify -spat before -bylist to enable slash patterns like \x0d\x0a example: :text /foobar/barfoo/ _the test_the text_ :binary /0d0a/200a/ :# remark and blank lines are skipped. :# the :text can be left out as it's default. about nested replacement patterns sfk replace myfile.dat /foo/bar/ /bar/goo/ with SFK base, "foo" will be replaced by "bar" and then immediately "bar" is replaced again by "goo". with SFK XE, a replaced part of text is never replaced again in the same command, so "foo" stays replaced by "bar". unexpected repeat replace behaviour depending on the input data and search/replace expressions, it can happen that running the same replace multiple times on the same file produces further hits that didn't exist in the first run. for example: - input file contains foothenbar - patterns are -text /then// -text /foobar// then this will happen with SFK XE: - on the first replace run, no "foobar" is found, but "then" is removed from text, producing a new "foobar". however, this new "foobar" is NOT replaced, because text processing already reached the position after "foo", i.e. the word "bar". - on the second replace run, a "foobar" is found that did not exist in the first run, and replaced. please note that there is no option to reiterate on the same file in one call of sfk replace, so re-replaces over newly combined text cannot be done automatically. SFK Base behaves slightly different, due to a different replace implementation, but it also does not reiterate. With a pattern sequence -text /foobar// -text /then// in the above example the same will happen with SFK Base. beware of Shell Command Characters. to find or replace text patterns containing characters < > | ! & you must add quotes "" around parameters, or the shell environment will destroy your command. for example, -pat /<br>/ / must be written like: -pat "/<br>/ /" examples sfk replace myfile.dat "/Lemon/Curry/" replace Lemon by Curry within myfile.dat. search is case-insensitive, therefore "lemon" will be replaced as well. the quotes "" are optional here. sfk replace -pat /FooCase// -dir . -file .txt search for FooCase in all .txt files below current directory. note that if you leave out the single fileOrDir parameter, you have to say -[s]pat, -bin or -text first to tell clearly that you will specify the target fileset later on. sfk rep -spat "/The foo/The\tbar/" -dir mydocs replaces "The foo" by "The" and "bar" separated by TAB char, within all files within mydocs. sfk rep -binary /1A/20/ -dir docs -file .txt .info .note replaces all bytes with code 0x1A by code 0x20, in all .txt, .info and .note files, in directory docs and all subdirectories. sfk replace tmp\image.dat -bylist patches.txt searches for source patterns in file tmp\image.dat, replaces by patterns specified in patches.txt sfk hexfind mydir -pat /FooCase/ +list -late do not replace, just find binary files containing "FooCase", then list them sorted by time. also accepts -bylist files. example with output: preparing a replacement of pattern "class Foo". [simulating:] [total hits/matching patterns/non-matching patterns] testfiles\FooBank\GUI\include\FooGUI.hpp: hit at offset 0x64 >6F6E616C 6974792E< onality. 00000054 >0D0A2A2F 0D0A0D0A< ..*/.... 0000005C >636C6173 7320466F< class Fo 00000064 >6F475549 0D0A7B0D< oGUI..{. 0000006C >0A707562 6C69633A< .public: 00000074 [001/1/0] testfiles\FooBank\GUI\include\FooGUI.hpp testfiles\Formats\12-foo-jam.txt: hit at offset 0xE6C >6F6E616C 6974792E< onality. 00000E5C >0D0A2A2F 0D0A0D0A< ..*/.... 00000E64 >636C6173 7320466F< class Fo 00000E6C >6F475549 0D0A7B0D< oGUI..{. 00000E74 >0A707562 6C69633A< .public: 00000E7C [001/1/0] testfiles\Formats\12-foo-jam.txt 38 files checked, 2 would be changed. [add -yes to execute.] the input data is listed as hex and ascii, with the hits highlighted. sfk is a free open-source tool, running instantly without installation efforts. no DLL's, no registry changes - just get sfk.exe from the zip package and use it (binaries for windows, linux and mac are included). read more about all sfk functions here.
|
|