1

I would like to be able to search a log file for lines that being with ^2014-02-18 15:30:[0-9:,]* and have UserName:someguy much later in the same line. I am sure I could do a regex to include any number of characters, digits and spaces before that point, but I would like to know if I could effectively do something like /^2014-02-18 15:30:[0-9:,]* | /UserName:someguy meaning pipe the results of the first search through the second search, while still in vim or less. Obviously I could do this with grep externally.

1
  • How about grep /^2014-02-18 15:30:[0-9:,]* | /UserName:someguy | vim -. It will open the contents in vim editor with only the lines having the above patterns in it.
    – Ramesh
    Feb 18, 2014 at 20:51

1 Answer 1

2
:v/^2014-02-18 15:30:/d

in vi deletes all lines except those matching that pattern. Then you can filter more with:

:v/UserName:someguy/d

Though you could do it in one go with:

:v/^2014-02-18 15:30:.*UserName:someguy/d

In less, type & and then ^2014-02-18 15:30:.*UserName:someguy

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .