I am getting confused with parameter substitution. Basically the file to be parsed is in the following structure:
foo.txt:
system.switch_cpus.commit.op_class_0::total 10000000 # Class of committed instruction
system.switch_cpus.commit.bw_lim_events 10000000 # number cycles where commit BW limit reached
system.switch_cpus.rob.rob_reads 80558432 # The number of ROB reads
system.switch_cpus.rob.rob_writes 43430539 # The number of ROB writes
system.switch_cpus.timesIdled 37218 # Number of times that the entire CPU went into an idle state and unscheduled itself
system.switch_cpus.idleCycles 2755508 # Total number of cycles that the CPU has spent unscheduled due to idling
system.switch_cpus.committedInsts 10000000 # Number of Instructions Simulated
system.switch_cpus.committedOps 10000000 # Number of Ops (including micro ops) Simulated
system.switch_cpus.cpi 8.369191 # CPI: Cycles Per Instruction
system.switch_cpus.cpi_total 8.369191 # CPI: Total CPI of All Threads
system.switch_cpus.ipc 0.119486 # IPC: Instructions Per Cycle
system.switch_cpus.ipc_total 0.119486 # IPC: Total IPC of All Threads
system.switch_cpus.int_regfile_reads 21773538 # number of integer regfile reads
system.switch_cpus.int_regfile_writes 9447282 # number of integer regfile writes
I want to find the following variables and print out the corresponding value:
list=(IPC CPI)
IPC="system.switch_cpus.ipc"
CPI="system.switch_cpus.cpi"
for i in $list:
do
awk -v a="$i" '{$1 == $a} {print}' $1
done
Then I run the script with the following command:
./parser.sh foo.txt
This is printing out the whole file.
Output:
system.switch_cpus.commit.op_class_0::total 10000000 # Class of committed instruction
system.switch_cpus.commit.bw_lim_events 10000000 # number cycles where commit BW limit reached
system.switch_cpus.rob.rob_reads 80558432 # The number of ROB reads
system.switch_cpus.rob.rob_writes 43430539 # The number of ROB writes
system.switch_cpus.timesIdled 37218 # Number of times that the entire CPU went into an idle state and unscheduled itself
system.switch_cpus.idleCycles 2755508 # Total number of cycles that the CPU has spent unscheduled due to idling
system.switch_cpus.committedInsts 10000000 # Number of Instructions Simulated
system.switch_cpus.committedOps 10000000 # Number of Ops (including micro ops) Simulated
system.switch_cpus.cpi 8.369191 # CPI: Cycles Per Instruction
system.switch_cpus.cpi_total 8.369191 # CPI: Total CPI of All Threads
system.switch_cpus.ipc 0.119486 # IPC: Instructions Per Cycle
system.switch_cpus.ipc_total 0.119486 # IPC: Total IPC of All Threads
system.switch_cpus.int_regfile_reads 21773538 # number of integer regfile reads
system.switch_cpus.int_regfile_writes 9447282 # number of integer regfile writes
How can create a list of variables in shell who have their own values and parse each of them from a file using awk or sed?