Friday, January 05, 2007

How to grep for the negation or not or something on the command line.

I've always wondered how to grep for the negation of something. When SubClipse messes up, I end up spending time in the terminal. I hate it. It should at least be able to recover from itself.

Anyway, I wanted to find the difference between two directories. So for diff, you simply use:

diff -rq directory1/ directory2/

And this will give you a slew of which files are different or same. But it'll give you all this stuff about .svn directories that you don't care about. So how do you grep for the NOT of something? I don't know, the regex for it (if someone cares to divulge, I'd appreciate it), but grep has a switch that does this for you:

diff -rq directory1/ directory2/ | grep -v 'svn'

And voila, it only gives you the differences other than paths with 'svn' in them.

5 comments:

  1. What sort of problems are you having with Subclipse? More than likely there is some sort of explanation. If nothing else, it could lead to a bug report being filed. We have a mailing list at users@subclipse.tigris.org where you can get help. Traffic is usually light and no SPAM comes through it.

    ReplyDelete
  2. Haha. It's a completely different thing all together to have the lead of Subclipse come and ask you about it. A bit embarrassing to say you hate someone else's work; it's frustration talking from getting sidetracked when trying to get work done. Thanks for being calm about it.

    Anyway, the problem is usually if a directory with .svn files are deleted outside of subclipse accidentally (or if a commit fails due to network problems); the svn files aren't correct.

    I have found that an 'svn update' on the command line usually fixes things, but sometimes, I end up having to check out things all over again, and diff the directories to make sure I'm not missing anything.

    The next time it happens, I'll note what went wrong and ask the list. Thanks.

    ReplyDelete
  3. If just the files are missing then svn update should put them back. However, if the .svn folder is missing, then you are right, you pretty much have to check out again. We have an FAQ about this on our website although it is written to a very specific but common scenario where the .svn folder is deleted.

    http://subclipse.tigris.org/faq.html#wc-not-locked

    Not that it matters, but the problem is in Subversion, not Subclipse. The command line would have just as much trouble once that folder is deleted.

    If your project is huge, you could checkout just the subset of the tree with the problem and then copy it into the right location of your existing working copy. Subversion should be able to handle it OK once you copy it back.

    ReplyDelete
  4. That makes sense. I think there are other instances where it seems to go awry, but I don't remember what they are. I'll post to the mailing list the next time it happens. The tip on checking out just the directory makes sense, I'll do that next time, thanks.

    ReplyDelete
  5. Anonymous6:02 AM

    ... or you could use:

    diff -rq directory1 directory2 -x .svn

    ReplyDelete