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 Answer
: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
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.