Strip off previous lines in tail or less

0

I'm using tail -f or less +F to observe a changing log-file. I know from a certain point the lines I'm looking for are going to appear.

So all that garbage before that point I don't require and would like to strip it off somehow.

Is there a way to accomplish that? Mustn't be tail or less, I'm not limited to that.

Qohelet

Posted 2018-02-26T13:27:59.000

Reputation: 103

Suppose the input were seq 100, and it was known that only lines greater than 50 had the needed lines. Let's say the needed lines are 61 and 63... is the goal to print from 61 to 100 (40 lines) or just 61 and 63, (2 lines)? – agc – 2018-02-27T06:54:33.053

I wish it was so clear. I see the program and the logs parallel and as a certain point in the program is reached I know the line I expect will appear in the next 3-5 seconds. Everything written in the log before that point is not relevant and I'd like to strip it off. – Qohelet – 2018-02-27T09:44:43.397

Answers

0

Use tail -F <logfile> | grep '<string>' and you'll only see lines containing <string>.

gmelis

Posted 2018-02-26T13:27:59.000

Reputation: 473

I don't know which string I'm waiting for. I just know the timeframe it will be read into the logfile. – Qohelet – 2018-02-27T09:32:55.767

So, you have something like from this time to that time like, 09:45:00 to 10:20:59, for example? awk could help in such a case, unless you want to write some parsing program using python, perl, bash, or any other scripting language. Or you could usesed's range feature, as in tail -F /var/log/syslog | sed -n -e '/ 09:45:/,/ 10:15:/p', to print all log entries from 09:45 to 10:15. – gmelis – 2018-02-27T10:13:35.327

There is a time in the beginning, but sometimes there are 50+ logs per second coming in (not always, but sometimes). It can be I have to split 11:31:33 in a half, and throw away everything before and everything past the first quarter of 11:31:36 is not so interesting too – Qohelet – 2018-02-27T10:31:42.377

Ok, there has to be something you're looking for. sed, awk, grep and piping can get you far enough, plus you can limit what you're searching for with regexes of the form /09:45:.*source_of_message.*begin_of_interesting_message/,/10:15.*end/ – gmelis – 2018-02-27T10:43:43.430

So far I mostly know what the entry doesn't look like. Mostly things like Client: gotNewMsg type M_TRANSACTION and other ones as they appear all over. So far I'm mostly looking for messages different to them and refer to specific objects (but I don't know how they are named, it's partly guessing too I fear) – Qohelet – 2018-02-27T17:55:38.017

In that case, why don't you start excluding lines? Finish off your command line with something like ..... | grep -v 'not_this\|nor_this\|neither_this', i.e ... | grep -v 'Client: gotNewMsg type M_TRANSACTION' – gmelis – 2018-02-28T18:37:27.703