2

I have a requirement to display all files in a directory which doesn't have CountOfFilesTransmitted=0 string in them.

If I give below command it gives only those files which has CountOfFilesTransmitted=1

find . -type f | xargs grep -l "CountOfFilesTransmitted=1"

Gives: 1.log, 2.log, 10.log

find . -type f | xargs grep -l "CountOfFilesTransmitted=1" -- gives 3.log, 7.log

There are logs in that directory with 0 to 100 files Transmitted I have to give 101 entries. Is there a way to get filenames which have non zero?

something like "find . -type f | xargs grep -l "CountOfFilesTransmitted!=0" which should return all files which doesn't have "CountOfFilesTransmitted=0" string.

2

This Answer will only work IF a file does not also contain the pattern of CountOfFilesTransmitted=0 assuming that the goal OP has is to show to files that contain that pattern at all.

find . -type f | xargs grep -le "CountOfFilesTransmitted=[1-9]"

using -e to allow for regex

  • @don_crissti Hmm... Very valid, Hadn't considered that as a possible outcome.. And yes, Just Did a test of the other question's answer, Definitely meets OP's needs.... Assuming of course his needs are as I understand them. – Gravy Oct 1 '15 at 22:14
  • Hi Gravy, Appreciate your reply! But there are few files with 100, 101 as well. If I use [1-1000]. It also finds 0 right? – kumar2008 Oct 1 '15 at 23:54
  • @kumar2008 The only question would be if a file might have both 0 and another one. This answer will find 100, 101, 1000, 10000. Essentially, matching that the first digit after CountOfFilesTransmitted is not 0, So it will find anything that isn't just 0, on the other hand it will not find 01 if you have that formatting it will fail. – Gravy Oct 2 '15 at 14:12
  • @kumar2008 let me know if that doesn't work for you and i'll work on another answer :) Assuming there isn't a correct answer in the other question – Gravy Oct 2 '15 at 14:21
  • Hi Gravy, sorry for late reply. had a rough day. I have tested and above command also brings files which has CountOfFilesTransmitted=0 when given [1-1000] – kumar2008 Oct 5 '15 at 21:39

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