I'm accessing a log file where I have the timestamps at the beginning of each log. So I'm extracting the time and storing it in a variable to later convert it to epoch time.
So the problem that I'm facing is that whenever I execute it, It says date: invalid date
and print the time stamps with a \n
next to it. example, 10/23/19 15:45:01\n10/23/19 15:45:11
. Also this output comes up in between when I'm printing the normal timestamps (this issue stops everytime I comment the date function)
I've tried doing it something like this:
error_time=$(
cat file |
grep -i 'word' -A 5 |
grep -o '[0-9][0-9]/[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
)
epoch_time=$(
date -d '$error_time' +%s
) or $(
date --date'$error_time' +%s(also +'%s')
)
for error_dir in $(ls -d $path)
do
for error_logs in $(ls $error_dir)
do
error_time=$(
cat $error_dir/$error_logs |
grep -i 'word' -A 5 |
grep -o '[0-9][0-9]/[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
)
epoch_time=$(
date -d '$error_time' +%s
) or $(
date --date'$error_time' +%s(also +'%s')
)
print $epoch_time
done
done
the expected output should be in epoch time(seconds as far as I know) and what I'm getting is like this
\n09/26/19 14:13:37\n09/26/19 14:34:31\n09/26/19 15:22:01
.