1

I have a rather large directory, and I like to search the files for occurrence of specific strings. I have a list of about 30 strings, and my directory is 1.3G. I tried adding all the strings to a file called

strings

Then I used grep -r -f strings . > grepresults But it takes a loooooong time. And I would not complain except I took a peek into the grepresults file, and the content does not seem to match any of my strings. I am doing something wrong. What should I do to see the result of my command immediately, and verify that it is what I want. Then I have no issue letting it run. Please let me know, and I'll post a sample of what it sends currently.

I issued grep -rFf foo -o and seems to get a whole bunch of irrelevant content. I do not know how to use stdout. Could you provide more detailed instructions please?

  • If the strings are patterns themselves then use grep -rFf strings . to treat them as fixed strings..also strings is not a good name for a file as there is an executable named strings.. – heemayl Aug 16 '15 at 19:51
  • @heemayl - Thanks. I get a similar result. It seems like it is matching everything. Is it somehow creating a file to process perhaps later? The output looks like none of the strings;-( – user3326293 Aug 16 '15 at 19:57
  • Perhaps there are only "source" files that should be searched. Then use ack, a.k.a. beyond grep – Basile Starynkevitch Aug 16 '15 at 20:02
  • You could a) simply use the output form stout, i.e. not redirecting it to a file and aborting it, and b) use the -o option to see how your strings are interpreted in the matches. – Fiximan Aug 16 '15 at 20:06
  • 2
    You probably don't want to place the output file in the directory you are searching. Also, when you redirect to a file, stdout is getting buffered, so you will see output in chunks that are the size of the file system block. – user3188445 Aug 16 '15 at 21:54
2

(Extracted answer from edit)

I got the result of the search by letting it run overnight. The command I used was:

@ubuntu:~/WORKING_DIRECTORY/LC_ALL=C fgrep -rFf bar > ~/myfile

Moving the results file, called myfile in the above command, definitely helped.

I also sorted the strings in the file. It was originally called strings, and I learned from one of the comments in this thread to change it to another name. So in the above command it is called bar. Using LC_ALL=C and fgrep instead of grep helped immensely. All the suggestions contributed to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.