Description:
I have code which extracts the time stamping's by matching a key word/sentence of a .log file which is existing in several folders of the form log_Job_*
.
It calculates time duration's of different processes and write the output to a .CSV file.
What columns I want to have in my .csv:
- FileName
- ProcessType
- Import
- Validate
- . .
- MainPartionDuration
Now the problem is, I have 2 types of process under 2. Process Type. So, thought of using case statements here. And did as following:
#!/bin/bash
cd /path/to/manoj/version_2019_logs/
for file in log_Job_*/manoj.log; do
ProcessType1="$(grep -F 'Running process mpeXbrlImport.xml' "$file" | awk '{print $5}' | cut -c 4-)"
ProcessType2="$(grep -F 'Running process mpeXbrlValidate.xml' "$file" | awk '{print $5}' | cut -c 4-)"
ProcessType="$ProcessType1","$ProcessType2"
case $ProcessType in
$ProcessType1)
#set of commands to get other variaqbles
Var="$Filename","$ProcessType","$TotalDuration","$Initialization","$MPEProcessDuration","$TotalPartitionDuration","$WaitPartitionDuration","$MainPartionDuration"
echo $Var >>OutputFile_Import.csv
;;
*)
#repeat the set of commands and this time save with different variable names
Var1="$Filename1","$ProcessType1","$TotalDuration1","$Initialization1","$MPEProcessDuration1","$TotalPartitionDuration1","$WaitPartitionDuration1","$MainPartionDuration1"
echo $Var1 >>OutputFile_Validate.csv
;;
esac
done
With this my plan is to create two separate .CSV files based on the Processtype
and then concatenate both the files.
Problem: The script is getting executed successfully, but at the end it is generating only one file i.e. OutputFile_Validate.csv
I have verified the script carefully, am not using any variables repeatedly. Can someone tell me, what could be the reason for this!!
If I understand well your problem, you want to feed import.csv when
ProcessType1
is not empty and validate.csv whenProcessType2
is not.You can
test
if the variable is set and not empty with:Your code could looks like: