0

I am trying to get all the .json files within a certain directory path, and to check if within each of the files found, if it contains a certain keyword. In this case, the keyword I am looking for is called "case_control".

So while I perform a very simple scenario - creating a few json file, some embedded with the keyword, it seems to run and is fast. However as soon as I run the code in the actual directory path that I want test it onto, it is taking quite some time.. like 2+ hours and it is still 'running'

Is my code wrong or does it simply works slow in linux?

This is the command I am using: find /serverA/data -type f -name "*.json" | grep -rn "case_control" /serverA/data

0

try this find command.

this will list out the filenames ( if the pattern is matched in that file )

find /serverA/data -type f -name "*.json" | xargs grep -l "case_control"
| improve this answer | |
  • Thanks, trying it out now.. While the result does not seems to be immediate, right now I am waiting again... – dissidia Jan 5 '17 at 1:53
  • how many files you have ? if you have huge number of files, then it will take time. – Kamaraj Jan 5 '17 at 1:54
  • about 1 to 2 hundreds? Actually your code is working.. I tried it with another keyword, and the result is almost immediate.. And I also just realize that because not all files contain the case_control keyword, I guess that is the cause of slowness.. – dissidia Jan 5 '17 at 1:58
  • 1
    yes, you are correct. But in your code, you are again running the grep command recursively against the directory. which is not correct – Kamaraj Jan 5 '17 at 2:00

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.