I'm using Bash shell to process some log files, which I need to put in a CSV file. The information I need is process start date and time, process end date and time , Process ID and message
What I did, grep lines including started process and put them in a file, then Grep ended processes and put them in a second file. Once done, I take each file, and use awk to split and extract the information needed, here is a peace of code I'm using,
input=starts.txt
while IFS= read -r line
do
procs=`echo $line | awk '{ print $6;}'
date_s=`echo $line | awk '{ print $1;}'`
time_s=`echo $line | awk '{ print $2;}'`
m1=`echo $line | awk '{ print $3;}'`
m2=`echo $line | awk '{ print $4;}'`
m3=`echo $line | awk '{ print $5;}'`
m4=`echo $line | awk '{ print $7;}'`
m5=`echo $line | awk '{ print $8;}'`
m6=`echo $line | awk '{ print $9;}'`
echo $procs ";" $date_s ";" $time_s ";" $m1 $m2 $m3 $m4 $m5 $m6
one < "$input" > result.csv
The lines have the following format :
02/01/2018 10:32:35 ANR4930I Reclamation process 1320 started for primary storage pool VM_VTL_POOL automatically, threshold=75, duration=None. (PROCESS: 1320)
I have two issues now :
- The while loop doesn't end.
- After extracting the time/date and process ID, I want to put the remaining message in a separate field, without taking word by word and concatenating them (m1 m2 m 3 ...) Also, if there is any improvements that can be done to my code.