Hi,
I want to add a value to a specific column of a file if that line starts with a pattern.
Samle file:
Quote:
ExecutionTime = 28.26 s ClockTime = 31 s
blabla
ExecutionTime = 53.7 s ClockTime = 59 s
bla
ExecutionTime = 77.28 s ClockTime = 86 s
yeah
ExecutionTime = 101.14 s ClockTime = 114 s
anyway
ExecutionTime = 123.02 s ClockTime = 140 s
|
I want to modify the two numerical values.
My utility function for this task:
Code:
timeCorrectLog()
{
local execTime=$2
local clockTime=$3
awk -F '[ \t"#]*' '/^ExecutionTime/{sub($3,$3+'$execTime')}1' $1 > tmpAWK
awk -F '[ \t"#]*' '/^ExecutionTime/{sub($7,$7+'$clockTime')}1' tmpAWK > timeCorrect.$1
rm -f tmpAWK
}
The command:
Code:
timeCorrectLog file 86728.8 95351
The output:
Quote:
ExecutionTime = 86757.1 s ClockTime = 95382 s
blabla
ExecutionTime = 86782.5 s ClockTime = 95410 s
bla
ExecutionTime = 95437806.1 s ClockTime = 86 s
yeah
ExecutionTime = 86829.9 s ClockTime = 95465 s
anyway
ExecutionTime = 86851.8 s ClockTime = 95491 s
|
Clearly, something went very wrong in line 5. I used the script for a huge log file, and it messed up only that line, have no clue what is happening!
In short, this is the command that causes the trouble:
Code:
echo "ExecutionTime = 86806.1 s ClockTime = 86 s" | awk -F '[ \t"#]*' '/^ExecutionTime/{sub($7,$7+95351)}1'
Thank you!