Originally Posted by
newbie01.linux
I am hoping that maybe someone from this FORUM know of any C program that I can use that can work like UNIX strings | grep "pattern"
At the moment, on a binary file, I am using UNIX strings and then grep for a pattern and print out that line and does some awk -F":" thing. This is manageable for when the binary file is 50M but not for where files are 100M and above. I mean it still works but takes longer since strings work on the entire file.
Basically the information that I am trying to extract from the binary file is some type of header that is contained in a file. I am thinking of maybe writing a 'simple' C program that will read the first few bytes of the binary file and then print the line that contains the string that I am looking for. I don't believe the header is at the end of the file but more in the beginning. I am wanting to extract the header information to be able to rename or make a copy of the binary in a more user-friendly name.
Maybe all you need to do is to avoid having grep read the entire file. Looking at my manual page for ack-grep, I see:
Code:
-m=NUM, --max-count=NUM
Stop reading a file after NUM matches.
If indeed the header is at the beginning of the file, I would hazard a guess that this would tremendously speedup the grep.
If you really do want to write a C program to do this, then a regex library like PCRE would be useful. But then you need to know how to program in C.