Search binary files?

How can I search through a folder full of binary files for a specific string (either hex or ascii) ?
i.e. I have a folder of 2,000 binary files and need to find one that has a specific string in it. Spotlight doesn't seem to be the ticket. I can't seem to find a sample file using grep.

The UNIX strings command can search for strings inside binary files. You can then use grep to find the string that you want.
strings files | grep desired_string
Mihalis.

Similar Messages

  • Fulltext search of binary files outside of database in SQL 2012/Server 2012

    This may be more of a Windows Server 2012 question but I'm not sure.
    I have a system that holds large amounts of binary files (pdf, doc, etc.).  The files themselves are held outside the database in a folder and a SQL table holds the metadata.  I used the Indexing Service available through Windows Server 2008 to
    create a catalog called "EFCATALOG" to index the contents of the external folder, then created a linked server called MYIDXS which allowed me to query that external indexing catalog from within SQL with a query like this:
    EXEC sp_addlinkedserver MYIDXS, 'Internal App', 'MSIDXS', 'EFCATALOG'
    SELECT * FROM MYDOCS
    LEFT JOIN OPENQUERY(MYIDXS,'SELECT FILENAME FROM SCOPE() WHERE CONTAINS (''test'')') AS MYTBL
    ON MYDOC_FILE_NAME = MYTBL.[FILENAME]
    With Windows Server 2012, I'm missing the functionality to create the indexing service catalog.  I've added the Windows Search Service and see how I can configure folders for searching, but there is no naming functionality for this and I don't see how
    I can get the above query/structure to work in Windows Server 2012/SQL Server 2012 environment.  In fact, there isn't much at all online regarding the search service or the relationship back to the older versions in 2008 and before.
    Is there any way to continue this structure in 2012?  I would like to avoid recoding my application to work with a different structure.  I'm afraid that changing everything to work with the FILETABLE/FILESTREAM functionality added in SQL 2012
    will be necessary which is fine long term, but not convenient right now.
    Thanks in advance for any suggestions/help.

    Thank you Fanny Liu, based on your link the syntax has changed dramatically. I need to query SYSTEMINDEX now and the structure is very different.    It still seems that this new syntax requires creating a linked server of a different type. 
    I've tried:
    EXEC sp_addlinkedserver @server = 'TEST', @provider = 'Search.CollatorDSO.1', @datasrc = 'SYSTEMINDEX', @srvproduct = '', @provstr='Application=Windows'
    SELECT FileName FROM OPENQUERY("TEST", 'SELECT Filename FROM SYSTEMINDEX')
    Msg 7302, Level 16, State 1, Line 1
    Cannot create an instance of OLE DB provider "Search.CollatorDSO.1" for linked server "TEST".
    I've also tried using just "Search.CollatorDSO"as the provider since that is the provider name listed in management studio but basically the same error comes back.
    So I have 2 questions:
    1) Is it possible for my original process to work in Windows Server 2012 in any way (meaning that the OPENQUERY example I provided can remain relatively unchanged)?
    2) If change is necessary using this new SYSTEMINDEX and linked server combination, why is my linked server definition failing?  I'm using SQL Server 2012....Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
     Feb 10 2012 19:39:15
     Copyright (c) Microsoft Corporation
     Express Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
    Thank you.

  • Searching binary data file

    Hi I have a data file which acts as a database. I need to search this file for records. I am trying to implement this in the most efficient way I have the following extremes
    1)To search using RandomAccessFile each record directly from the file
    2)Load the entire file into memory. By encapsulating each record in a lava object.
    1st option would save me a lot of memory but time consuming . The second option would consume a lot of memory and might be unsuitable for a large amount of records.
    I have chosen a middle path but I am not sure if it will work properly.
    My current proposal is to use a scaled down Object to represent a record
    Integer values which are mostly 8 bit and 16 bit value will be stored an a array of integers where the necessary values are stored and extracted using bitwise operations.
    My problem is characters I was thinking of storing the hash code of the Strings but the search protocol requires that you should be able to search even if a part of the String is given.
    Regarding this problem I looked up the java 1.5 API doc for String.hashCode. Where I determined the hash code of a substring is smaller than of the main String. My question is? Is it possible to use this as a search condition to initially eliminate certain records and then read the character sequence from the file to confirm my match.
    I hope you can understand what I have typed above and any help would be appreciated.

    Why not turn this thing into a database and actually use database drivers to query it, and let the database worry about those kinds of things rather than basically reinvent them yourself?

  • How do I create a binary file using PL/SQL

    Hi
    Can you help me with writing a binary file in PL/SQL? I like to load binary data from data file, process in database then write to a new binary file.
    Thank you very much in advance.
    regrds
    Yongdong

    DBMS_LOB won't help you write a BLOB to disk.
    You need to an external procedure to do that. Eric K's java works great and he's helped me with his solution and probably about a thousand others.
    Doing a search on this forum will yield many discussions on this often regurgitated topic.

  • The first binary file write operation for a new file takes progressively longer.

    I have an application in which I am acquiring analog data from multiple
    PXI-6031E DAQ boards and then writing that data to FireWire hard disks
    over an extended time period (14 days).  I am using a PXI-8145RT
    controller, a PXI-8252 FireWire interface board and compatible FireWire
    hard drive enclosures.  When I start acquiring data to an empty
    hard disk, creating files on the fly as well as the actual file I/O
    operations are both very quick.  As the number of files on the
    hard drive increases, it begins to take considerably longer to complete
    the first write to a new binary file.  After the first write,
    subsequent writes of the same data size to that same file are very
    fast.  It is only the first write operation to a new file that
    takes progressively longer.  To clarify, it currently takes 1 to 2
    milliseconds to complete the first binary write of a new file when the
    hard drive is almost empty.  After writing 32, 150 MByte files,
    the first binary write to file 33 takes about 5 seconds!  This
    behavior is repeatable and continues to get worse as the number of
    files increases.  I am using the FAT32 file system, required for
    the Real-Time controller, and 80GB laptop hard drives.   The
    system works flawlessly until asked to create a new file and write the
    first set of binary data to that file.  I am forced to buffer lots
    of data from the DAQ boards while the system hangs at this point. 
    The requirements for this data acquisition system do not allow for a
    single data file so I can not simply write to one large file.  
    Any help or suggestions as to why I am seeing this behavior would be
    greatly appreciated.

    I am experiencing the same problem. Our program periodically monitors data and eventually save it for post-processing. While it's searching for suitable data, it creates one file for every channel (32 in total) and starts streaming data to these files. If it finds data is not suitable, it deletes the files and creates new ones.
    On our lab, we tested the program on windows and then on RT and we did not find any problems.
    Unfortunately when it was time to install the PXI on field (an electromechanic shovel on a copper mine) and test it, we've come to find that saving was taking to long and the program screwed up. Specifically when creating files (I.E. "New File" function). It could take 5 or more seconds to create a single file.
    As you can see, field startup failed and we will have to modify our programs to workaround this problem and return next week to try again, with the additional time and cost involved. Not to talk about the bad image we are giving to our costumer.
    I really like labview, but I am particularly upset beacuse of this problem. LV RT is supposed to run as if it was LV win32, with the obvious and expected differences, but a developer can not expect things like this to happen. I remember a few months ago I had another problem: on RT Time/Date function gives a wrong value as your program runs, when using timed loops. Can you expect something like that when evaluating your development platform? Fortunately, we found the problem before giving the system to our costumer and there was a relatively easy workaround. Unfortunately, now we had to hit the wall to find the problem.
    On this particular problem I also found that it gets worse when there are more files on the directory. Create a new dir every N hours? I really think that's not a solution. I would not expect this answer from NI.
    I would really appreciate someone from NI to give us a technical explanation about why this problem happens and not just "trial and error" "solutions".
    By the way, we are using a PXI RT controller with the solid-state drive option.
    Thank you.
    Daniel R.
    Message Edited by Daniel_Chile on 06-29-2006 03:05 PM

  • Word saving documents as binary files- can't send documents as attachments

    I've had my Macbook for about 9 months. During the first 6 months, I could send attachments via email perfectly fine. After about 6 months, something happened and the files could no longer be opened after being attached. I tried sending some attachments to myself and found out that the documents were being sent as binary files.
    I also backed up my documents onto an external hard drive. When I opened the documents on a Windows computer, the Word documents that I created during the first 6 months could be opened. However, the most recently created documents couldn't be opened by my computer.
    I decided to do an erase and install on Saturday. Afterwards, Word was working fine and I was able to send documents as attachments. This morning (Tuesday) I tried to send attachments again and it didn't work! Again, the documents were binary files.
    I'm not sure what to do because it was working fine for three days, but now it's not working anymore. I think something must have happened during those three days that corrupted my computer?
    Has anyone had a similar problem? Can anyone help?
    Sorry I know it was a long post but I wanted to give more information in case it would give some clues. I feel I should add that I've been having quite a few problems with my Macbook, e.g. screen freezing, DMGs not loading properly, getting some pop ups
    Message was edited by: MissIndecisive
    Also wanted to add that I've had my logicboard replaced recently because of problems such as freezing, so I don't think it should be a hardware problem.

    Since Word is not an Apple product, you'll get better response if you use a forum dedicated to Microsoft's Mac products such as <http://groups.google.com/groups/dir?sel=33607053> rather than an Apple forum that focuses on compatibility between Macs and Windows.
    Be sure to search the forum first in case someone has already had a similar question answered. You'll get your answer faster this way. Post your question in the forum if you don't find anything that helps you

  • How to upload binary file in database?

    Using servlets..how to upload binary file into database...
    How to get the data of file in servlet...
    Please reply...i'm unable to find exact code...that i want..

    You need to do two separate parts: accept the file from a HTTP multi-part POST and then stream it into a BLOB on the database. To do the former, download Jakarta Commons FileUpload. There is extensive documentation on how to write a simple handler for the upload. You then need to send the data to a BLOB. The specifics vary from database to database but generally you will insert or update a row with an empty blob, get a reference to the blob, pipe the data and then commit.
    If you do a quick forum search, this question has been asked (and answered) dozens of times. Some of the replies may even have code for you. Best of luck.
    - Saish

  • Binary file compare

    I'm sorry. I didn't want to have to post here, but I've been banging my head on this all week. Hopefully somebody here can shed some light on this for me.
    I'm trying to write an application that compares a series of binary files in a user-defined order. The user needs to be able to specify the type of change that has occured ( > < = !, and numerical searches) for a given byte. (I am also supporting WORD/DWORD, but it's the same principal) To clarify, imagine:
    Byte at given offset: (((fileA < fileB) = fileC) != fileD) ...
    Now, my original code worked, but it was extremely poor. It had two methods fullCompare() and partialCompare(), it read data directly from the DataInputStream, and used skipBytes() to pass over bytes that had been excluded from a previous search. I kept thinking "There has to be a better way to do this." So I made it as simple as possible! I created an inner class called BinaryFile. BinaryFile reads the data (using getUnsignedByte() getByte() getUnsignedShort() getShort() etc... depending on the user's option.
    I created two instances of this class... One I call 'result' and the other 'bin' the files are read in by the constructor and stored in an ArrayList<Integer> (later I cast my Shorts to int)
    Now, 'result' holds the first file opened, and bin holds each additional file, ex:
    BinaryFile result = new BinaryFile("C:\\test1.bin", BinaryFile.UNSIGNED_WORD);
    All of this works�. OK, so now I run my first compare:
    compare(new BinaryFile("C:\\test2.bin", BinaryFile.UNSIGNED_BYTE), GREATER_THAN);
    again, everything works like a champ.. now to actually compare the files, I do this:
    public void compare(BinaryFile bin, int compareType) {
    for (int count=0; count < results.values.size(); count++) {
    if (results.values.get(count) != null) {
    switch (compareType) {
    case GREATER_THAN:
    if (bin.values.get(count) > results.values.get(count))
    results.values.set(count, bin.values.get(count));
    else
    results.values.set(count, null);
    break;
                        ����������..
    Now, it works for the FIRST two files that I compare, but after that it's like it started setting null when it wasn't supposed to�. I know that nobody probably read this far, but somebody please help me, this is killing me.

    I posted that at some unruly hour of the morning, while tired and frustrated... I had a flight from Korea to Japan today and spent the entire trip reading J2SE 5 docs about collections and generics, etc... So I'm going to give this one more go-round before I ask for help. I hate being beaten by a machine, asking for help makes me feel like I lost!
    Thanks

  • "Read From Binary File" function Help ambiguity

    I must be getting tired, but for some reason a doubt crept in my mind as I was designing a new piece of code this morning:
    "is the "Read From Binary File" using the last file position or is it starting from the beginning of the file?"
    "That's a stupid question", I told myself.
    "I used this function a million times and have always assumed it is reusing the last file position. Moreover, there is no file offset input to that function, so WTH am I afraid of?"
    So, for kicks, I fired up the Help window and read the following description (*):
    Reads binary data from a file and returns it in data. How the data is read depends on the format of the specified file. This function does not work for files inside an LLB.
    (*) BTW, has anybody ever complained that you can't select and copy anything from the floating Help Window?
    Not much there. I particularly admire the phrasing of the second sentence... What about: "This function can do a lot of things, but it would much to complex to describe this is extensive details, so if you are asking, you probably can't afford using it"?
    Anyhow, I clicked on the "Detailed Help" and got this (among other things):
    Use the Set File Position function if you need to perform random access.
    WHAT? I am pretty darn sure I DO NOT USE the Set File Position when I read a file in successive and contiguous chunks. I just pass the file refnum into a shift register and back to the function and that's it.
    Now, the description of the "Refnum Out" ouput says: If file is a refnum or if you wire refnum out to another function, LabVIEW assumes that the file is still in use until you close it. Translated in plain English, is that supposed to mean that if the file is not closed it is open, or is that implying that it contains more info that just "the file is open and can be found here"?
    I started searching around and finally ended up with the entry for "refnums, file I/O". Down the bottom of the (long) article, I found this under the heading "References to Objects or Applications" (but nothing specific to files, BTW):
    ...LabVIEW creates a refnum associated with that file, device, or network connection...
    [...]  LabVIEW remembers information associated with each refnum, such as the current location for reading from or writing to the object and the degree of user access, so you can perform concurrent but independent operations on a single object. If a VI opens an object multiple times, each open operation returns a different refnum. LabVIEW automatically closes refnums for you when a VI finishes running, but it is a good programming practice to close refnums as soon as you are finished with them to most efficiently use memory and other resources.
    So it seems that my recollection was correct. I do not know what the "degree of user access" for a file is, but that's not the topic of today's post. 
    So, my point is: the Help File for this function is incomplete or ambiguous at best. Please correct it. And provide a link to the "refnum, file I/O" Help entry in its detailed Help. It would H E L P...
    Thanks for reading.

    Reading in succesive chunks is *NOT* random access. An open file always has
    a current position, which is updated with each read or write operation.
    You only need to set the file position if you want to start elsewhere.
    LabVIEW Champion . Do more with less code and in less time .

  • Binary file import and export in lab windows cvi

    Hello,
    I have some standard binary file format (.sie) that has been written in origin IDE. The sie type extension file format is a public format, but not defined by Origin. In origin IDE, i can be able to import these files and also be able to export it to excel as csv type. Now, i want to do the same thing in lab windows cvi. i need to import .sie type file and be able to read and export it to excel in lab windows cvi. Is this possible? Please help me to work on this project. Thanks in advance.
    Regards,
    Jayakumar.V

    Reading and writing binary file is indeed possible in CVI, the problem normally lien in the definition of the file format you want to access.
    I never found .SIE extension during my activity; a fast search on google returned this page with a link to the document explaining one file structure: it's a format dedicated to accounting so it's possibly not  your case, but could they be your files?
    Before finding the complete description of the file format you cannot think of any operation on the file itself, unless it is so self evident that you need little effort to access file content (this normally happens only on text files).
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Read binary file in as string to perform RegEx

    I have a python script that I use to gather data from a particular data file. I want to convert the script into a java application so I can add a gui and make it more distributable. I am particularly struggling on how to read the binary file into java and convert it to a string for the regex searching.
    import re
    dat = 'c:/projects/test.dat'
    all_the_data = open(dat,'rb').read()
    pattern = 'title="(.*?)".*?value="(.*?)"'
    rx = re.compile(pattern, re.IGNORECASE|re.MULTILINE|re.DOTALL)
    result = rx.findall(all_the_data)
    for title, value in result:
        print "%-25s: %s" % (title, value)

    Hi infraray.
    Check my post out: Cyclomatic Complexity Using Regex .
    This will help.
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.io.*;
    1) static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
    2) protected String txtFileName;
    3) System.out.println("Enter file name to be read: " );
    4) txtFileName = new String(keyboard.readLine());
    5) reader = new BufferedReader(new FileReader(txtFileName));
    // Your Pattern |
    V
    6) Pattern pattern = Pattern.compile("if|for|while|case|switch",Pattern.MULTILINE);
    7) Matcher m = pattern.matcher(txtFileName);
    8) boolean b = m.matches(); // return true if match found !
    9) String line = null;
    10) while((line = reader.readLine()) !=null)
    m.reset(line);
    if(m.find())
    // Change line below to suit your need
    System.out.println("Your message " + " found " + " start of line: " + m.start() + " ends at line: " +m.end());
    reader.close(); // close buffered reader!
    Hope this gives you some direction.

  • Binary files in java

    hi
    I am a bit new to java and am having some problems with binary files. What I need to do is search a binary file for any accurances of the data contained with in another set of binary files. I need to know if the first file contains any of the signatures in the set of files. any help would be great.
    thanks very much
    Colin

    you take your file, you read in some bytes and you loop thru those bytes to find matching bytes that you are looking for. Here's some cdoe that's probably not as elegant as it could be, but you get what you pay for.
    public static int indexOf(byte[] a, byte[] b) {
       return indexOf(a, b, 0);
    public static int indexOf(byte[] a, byte[] b, int start) {
       if(a == null || b == null || a.length == 0 || b.length == 0 || a.length < b.length) {
          return -1;
    outer:   for(int i = start; i < a.length-b.length; i++) {
          if(a[i] == b[0]) {
             for(int j = 0; j < b.length; j++) {
                if(a[i+j] != b[j]) {
                   break outer;
             return i;
    }

  • Sending binary file via RS232 connection

    Hi,
    I want to send a binary file via RS232 connection but I have troubles reading the .bin file and then converting the data to string in order to send it via RS232. Any ideas how i can deal with this?
    Thanks in advance,
    IG. 

    It is hard to help then you do not post any code. I suggest you go to the toolbar then help. Then you select Find Examples. Search for files. Also since you are new to Labview always have context help enabled. Both tools are important if you want to learn Labview. Feel free to post again if you are stuck.
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • How read just a part of a binary file?

    I want to read only a part of a big binary file.
    I have made a piece of labview code that works well, but every time I try to read only a part of the file, I have an error.
    I try to search where I have make a mistake in the code, but dont find.
    Just for information : at the end of the code, I just display 1 data of 5.
    Thanks in advance.
    Attachments:
    LECTURE-ZOOM.vi ‏66 KB

    Johnsold.
    Thank you for your answer.
    I have tested you vi LECTURE-ZOOM.2.vi, and I think there is some problems with my application.
    First, let me transduce the vi into words : if columns index is more than the max columns value, then you stop, and the same think with the rows index.
    With the sift register you make a memory allocation for the array that changes every loop.
    By doing this way, I have two problem.
    When I read a big file, the memory allocation takes a lot of memory, because the array allocation in memory changes every loop.
    Besides, when I run the vi, the columns and rows are completly wrong, because, the command "chanel number is not respected : if I put 7 chanels, I have 5 chanels on the array.
    Then, When I have it, I compare the "sortie" array versus "entrée" array, and I seems that AFTER decimation (1 point taken on 5), I have more points at the end than at the begining.
    I give you a sample of a data file (compressed in zip...) to test your vi.
    It's a 6 chanels data file, puted in a array.
    When I try to run the vi you modify for me, I seems that it doexn't work because the result was totaly wrong... :-(
    I think that I make a mistake/error in the vi understanding, because I try to change some parts of your vi, to adapt it to my application, but it doesn't work.
    What do you think about my way of read the datas?
    How can I change the vi to obtain the same array than in mine.
    To see what I obtain, just lunch the vi in my next post with the data file in this post.
    Attachments:
    buffer01.zip ‏1201 KB

  • Problems writing a structured binary file...

    Hi Folks,
    I've been working with one of my students to convert this matlab routine into a VI to no avail:
    fwrite(fout,version,'char');
    fwrite(fout,nchar_text,'short');
    % convert wave_text into array of ascii integers
    fwrite(fout,wave_text,'char');
    % output a null character to terminate string
    %count=fwrite(fout,0,'char');
    fwrite(fout,n_bits,'char');
    fwrite(fout,n_bytes,'char');
    fwrite(fout,data_polarity,'char');
    fwrite(fout,user_data,'float');
    fwrite(fout,s_rate,'ulong');
    fwrite(fout,adrange,'float');
    fwrite(fout,n_pts,'long');
    fwrite(fout,wave,'short');
    fclose(fout);
    I've written a VI that can open the files written by this Matlab procedure with no problem (see openfile.VI), however I can't seem to recreate the method for writing this file to binary (writefile.VI).  I think the Matlab approach is very similar to C, and I'm guessing the issue has to do with converting datatypes effectively.  I've been searching the forms and google, but can't seem to come up with the proper solution.  Any pointers would be greatly appreciated!
    Best,
    Jason Gallant
    Attachments:
    writefile.vi ‏27 KB
    openfile.vi ‏26 KB

    crossrulz wrote:
    The additional bytes for the array and string lengths is what is throwing you off.  Even if you turn it off at the Write Binary File, because you built a cluster they will be in there.  You do not want to cluster up your data in this case.  You need to string together a bunch of Write Binary Files, one for each of your parts of data.  Similar to what you had to do in Matlab.
    Great suggestion!  We tried implementing this, and things are looking better.   I've attatched the new VI that implements this.   There still seems to be a problem, however with the datatypes being written.  As mentioned in the previous post, the data written is:
    version   - 'char
    nchar_text, 'short'
    wave_text, 'char'
    n_bits,'char'
    n_bytes,'char'
    data_polarity,'char'
    user_data,'float'
    s_rate,'ulong'
    adrange,'float'
    n_pts,'long'
    wave,'short'
    Should i be typecasting (or something similar) to string in order to make this readable by my previous routine?
    Attachments:
    writefile.vi ‏38 KB

Maybe you are looking for