Iva*_*anH 4 windows linux search
我有一个二进制文件,我需要计算该文件中某个字符串的出现次数,甚至是列表中的偏移量。在 Windows 或 Linux 中 - 对于此任务,我使用 Fedora 12 和 Windows 2000。
在带有GNU grep 的Linux 上:
grep -F --text -o --byte-offset mystring binaryfile
Run Code Online (Sandbox Code Playgroud)
例子:
$ grep -F --text -o --byte-offset option /bin/tar
226542:option
237529:option
237612:option
...
Run Code Online (Sandbox Code Playgroud)
参数说明:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines,
any of which is to be matched. (-F is specified by POSIX.)
-a, --text
Process a binary file as if it were text; this is equivalent to the
--binary-files=text option.
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with
each such part on a separate output line.
-b, --byte-offset
Print the 0-based byte offset within the input file before each line
of output. If -o (--only-matching) is specified, print the offset of
the matching part itself
Run Code Online (Sandbox Code Playgroud)
要计算出现次数,请添加| wc -l
到命令行。
归档时间: |
|
查看次数: |
2939 次 |
最近记录: |