0

I am using the following complex command pipeline to find all files whose name ends in .xma or .sma, then find a certain string in them and sort the results. This is to find all files for a certain application on my system to see which versions I have used (important for upgrading, migrating).

find . -path ./Library/Mail -prune -or -path ./Documents/Architecture/BiZZdesign_Profiles \
-prune -or -name \*.\[sx\]ma \( -exec grep -H lastSavedWith {} \; \
-or -exec grep -H createdBy {} \; \) |\
sed -E 's/([^:]+).*(Architect|Enterprise Studio) ?([^<]+).*/\2 \3: \1/'|sort

This works well, and I get my list. But files created with really old versions of this application have no such string at all. Hence, I need to find any file that has a name ending in .xma or .sma, but without any of the strings 'lastSavedWith' or 'createdBy' in them. Is there a way to do that?

gctwnl
  • 217
  • 1
  • 8
  • 1
    Since you're using grep, you can do a [negative match](http://stackoverflow.com/a/3548465/2583665) using `grep -L`. – adanmoran May 05 '17 at 13:30
  • Add `|grep -v `. `-v` means that grep will filter out the unwanted string. – Michael May 05 '17 at 13:31
  • Nope. It will give a positive match (on all the lines in the document not matching that string). grep -L was the answer. – gctwnl May 06 '17 at 14:15
  • With -L it is possible, but one must use a single egrep command with a regex that contains all strings that should not be there. Because grep will return OK (0) if it checks a file and the string actually is there, even if it does not put the file name to output. So, the alternative is find . -path ./Library/Mail -prune -or -path ./Documents/Architecture/BiZZdesign_Profiles -prune -or -name \*.\[sx\]ma -exec egrep -L -H '(lastSavedWith|createdBy|lastConvertedBy)' {} \; |sort – gctwnl May 06 '17 at 14:50

0 Answers0