Please find below my approach to the initial question:
Possible solution
$ (head -1 requests.log; tail -1 requests.log) |
tr -s ' ' |
cut -d ' ' -f4 |
awk '{printf( "%.3f\n", $1/1000);}' |
xargs -I T date --date=@T
Mon, May 2, 2022 9:47:57 AM
Mon, May 2, 2022 9:57:56 AM
Explanation
$ cat requests.log
REQUEST test 1 1651474077633
REQUEST test 0 1651474077630
REQUEST test 1 1651474077631
REQUEST test 2 1651474077632
REQUEST test 3 1651474077633
REQUEST test 4 1651474676561
Step 1 - Get the first and the last lines
$ (head -1 requests.log; tail -1 requests.log)
REQUEST test 1 1651474077633
REQUEST test 4 1651474676561
Step 2 - Trim multiple white spaces
$ (head -1 requests.log; tail -1 requests.log) |
tr -s ' '
REQUEST test 1 1651474077633
REQUEST test 4 1651474676561
Step 3 - Get the timestamps
$ (head -1 requests.log; tail -1 requests.log) |
tr -s ' ' |
cut -d ' ' -f4
1651474077633
1651474676561
Step 4 - Convert timestamps to seconds
$ (head -1 requests.log; tail -1 requests.log) |
tr -s ' ' |
cut -d ' ' -f4 |
awk '{printf( "%.3f\n", $1/1000);}'
1651474077.633
1651474676.561
Step 5 - Convert timestamps to human readable dates
$ (head -1 requests.log; tail -1 requests.log) |
tr -s ' ' |
cut -d ' ' -f4 |
awk '{printf( "%.3f\n", $1/1000);}' |
xargs -I T date --date=@T
Mon, May 2, 2022 9:47:57 AM
Mon, May 2, 2022 9:57:56 AM