Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 at 20:51

1 Answer 1

: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

share|improve this answer

Your Answer

 
discard

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.