Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 '14 at 20:51
:v/^2014-02-18 15:30:/d

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


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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.