How to search for lines in file between two timestamps using Bash?

How to search for lines in file between two timestamps using Bash?

Probably every scripting language out there (perl, python, ruby, lua) has builtin or library support for parsing time and date. and plug that into Tiago’s sed filter idea. Run it from command line using syntax : ./p.pl A_22:09:14.

How to test file times in Linux shell?

In testing on this linux system. The usual way to test file times is the shell: Seems to work with seconds. This, which will touch the files with a time difference less than a second, doesn’t detect that difference: The file1 is (a bit) newer than file2.

How to find the last modified date of a file?

I solved the problem this way: get the current date and last modified date of the file (both in unix timestamp format). Subtract the modified date from the current date and divide the result by 60 (to convert it to minutes). expr $(expr $(date +%s) – $(stat mail1.txt -c %Y)) / 60 Maybe this is not the cleanest solution, but it works great.

How to check file modification time in seconds?

AFAICT, macos doesn’t seem to even store sub-second time information in the file attributes on the HFS+ file system at least. On OSX and Linux, date -r seems to work well, I use date -r “$file” +%s to get the modification time in seconds since epoch like so:

Is there a command line to match timestamps?

The above command line implements right-open time interval matching. To get closed interval semantics just increment your right date, e.g.: In case you want to match timestamps in another format you have to modify the $0 ~ /^\\ [/ sub-expression. Note that it used to ignore lines without any timestamps from print on/off logic.

How to extract logs between two time stamps?

Please note the start time stamp or end time stamp may not be there in the log, but I want every line between these two time stamps. The above command line implements right-open time interval matching. To get closed interval semantics just increment your right date, e.g.:

How to grep between two timestamps in SED?

For example If I use below command prints the output please suggest how to use sed command to grep between timestamps, if log file doesn’t contain starting timestamp and ending timestamp but contains logs between timestamps.