I want to extract every thing in that file listed between a given start time and an end time.
so some thing like all events between
the first entry of 12:01:00 and the last entry of 12:03:59
and store them in a random text file. Note time stamps can be repeated and therefore I mentioned the first and the last entries.
And not all lines in the log file start with a time stamp. Some lines are just random information about the server etc. But I want to extract those lines as well.
Hope I have clarified my question.
And thanks in advance every one
ali
Use CODE tags when posting code, data or logs for better readability and to preserve formatting like indention etc., ty.
So here we use the grep command to search for multiple "arguments", delimited by the pipe (|) symbol in the <input_text_file_name> and then redirect with the > to the <output_text_file_name> and then you should have the results you want in the <output_text_file_name> file.
This may not meet all the requirements.
Remember the requirement says:
"""And not all lines in the log file start with a time stamp. Some lines are just random information about the server etc. But I want to extract those lines as well."""
This pattern doesnt do anything :
sed -n '/^12:00/,/^12:03/p' event.log > new_event.log
And the grep ones I believe will only extract lines that contain the pattern that I have entered. But they would miss the lines in between. I do need the lines without the pattern as well.
I again summarise my requirement:
In a file extract every thing from the first occurance of pattern: 12:01:00 till the last occurance of pattern: 12:03:00.
I have no issues.
Is it possible your input file is DOS formatted?
Here is my working.
cat event.log
12:00:07 event 0 happened.
some line at 2
12:01:01 event 1 happened.
some line at 4
12:01:05 event 2 happened.
12:01:30 event 3 happened.
some line at 7
some line at 8
12:02:01 event 4 happened.
12:02:40 event 5 happened.
12:03:40 event 6 happened.
12:04:06 event 6 happened.
Command:
sed -n '/^12:00/,/^12:03/p' event.log
Output:
12:00:07 event 0 happened.
some line at 2
12:01:01 event 1 happened.
some line at 4
12:01:05 event 2 happened.
12:01:30 event 3 happened.
some line at 7
some line at 8
12:02:01 event 4 happened.
12:02:40 event 5 happened.
12:03:40 event 6 happened.
May be version issues?
Remove the "> new_event.log" part and check.