5

If I want to show only lines that content "Buy" I use command occur:

Like this: enter image description here

enter image description here

Nice.

But I need to show lines that content "Buy" and 0.00000057

So the result must like this enter image description here

How I can do this by occur command?

4

If you know that BUY always comes before 0.00000057, you can give occur the regex BUY.*0.00000057.

That will search for all lines that have BUY, any number of characters, then 0.00000057 in it.

Alternate package

If you use helm swoop, not only can you specify them in either order (swooping for BUY 0.00000057 is the same as 0.00000057 BUY), but you also get live results, and easier navigation between them.

6

If you only care about a particular order (e.g. Buy comes first) then you can use a regexp: Buy.*0.00000057, as mentioned by @zck. But if you need to check for both orders then a single regexp won't do the job.\

To match multiple things in any order, here are two approaches.

  • Use occur, refining its output with multiple patterns.

    1. Use M-x occur Buy to get matches for Buy in buffer *Occur*.
    2. Use C-x C-q in buffer *Occur*, to make it modifiable.
    3. With the cursor at the top of *Occur* (M-<), use M-x keep-lines 0.00000057, to keep only lines that also match 0.00000057.

      • This technique works with all kinds of buffers, including *grep* output, for instance. Repeat keep-lines to match as many patterns as you want.
      • You can also use the dual command flush-lines, to remove lines that match another regexp. You can use flush-lines and keep-lines any number of times, to refine matches.
  • Alternatively, if you use Icicles then you can use any number of patterns together, to match things in any order (for any matching context). Each pattern can be a regexp, literal string, or fuzzy-match pattern.

  • 1
    "single regexp won't do" - Technically, the single regexp Buy.*0.00000057\|0.00000057.*Buy should work. Not that I would recommend it though. – npostavs Jan 26 at 14:10
  • @npostavs: Nor would I. But more important is the general case - any number of things to match, in any order. – Drew Jan 27 at 2:25

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.