2

I have a file (a log) with unique identifiers. I know I can exclude a single unique identifier in emacs using M-x flush-lines. I sometimes need to exclude more than one unique identifier, and for up to ten or twenty this is not a problem as I can do it by hand. This is usually sufficient for my needs. However, there is the occasional need to exclude significantly more. Today, for instance, I need to exclude some 80k instances of unique identifiers (out of a file that might have over 300k unique ids. (I'm trying to locate the proverbial needle in a haystack and have a way to identify one kind of 'not needle' that is present 'and now I need a way to get them out of the way quickly)

Is there a way to loop through flush-lines over a list of regex? (and when I say 'loop', I'm purely being descriptive: I don't, necessarily, mean the function loop. I'm given to understand 'while' and 'dolist' are similar functions... I don't know how to use any of them in this case)

Thanks.

  • 1
    Just to clarify, do you mean you want to run flush-lines 80K times, each time with a different regexp? This might be easier to do from the command line via grep -v. – Tyler Feb 27 '17 at 21:53
  • Yes, Tyler, that's essentially what I mean. I thought of the grep -v (egrep, actually) option but each instance of exclusion leaves me with a file that thats got the remaining 79,999 regex 's and I have to, it seems to me, iterate on the file creation. Much simpler, I would think, to let emacs buffer manage to do it... But, as you may have gueessed, I'm not a programmer... – Petr Feb 27 '17 at 22:00
  • This might get you started: gist.github.com/plantarum/80937e21cde1f51764ee3727f92a50a6 – Tyler Feb 27 '17 at 22:16
  • 1
    Certainly you can do what you want. Obtain a list of the identifiers (from reading a file or whatever), then use dolist over the list, calling flush-lines for each (from point-min each time). This is just as easy and performant as combining them into a single regexp \(foo\|bar\|...\) and using a single invocation of flush-lines. (And such a large combination regexp might lead to regexp overflow.) – Drew Feb 27 '17 at 23:50
1

You might like to read those 80K identifiers, then combine them into a single regexp with regexp-opt and then pass that to a single flush-lines call. This said, maybe it'll fail because the resulting regexp is too large (Emacs has a limit on the size of its regexps).

| improve this answer | |
  • 1
    Note that regexp-opt takes literal strings, not regexps. If you include e.g. an anchor in your regexps you'll have to factor it out. – YoungFrog Feb 28 '17 at 8:32

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.