I don't see how your code could work at all. Your regex won't match any of the lines you've shown, so $1 and $2 are going to be empty. You've got TWO format items in your printf(), but you're only supplying ONE item to that format list. And you've got a precedence problem with the
?: operator and addition. Try this:
while (<>) {
if (/^(\w+)\s+(\d+)(.*)/) {
printf "%s %d %s\n", $1, (exists $disk{$1} ? 0 : ($2+$partition)),
+ $3;
}
else { print }
}