Here we read each line from the costs text file,
skip lines that don't start with digits,
extract the product and cost,
apply the margin (or a default),
apply the note (or a default),
and write the output.

Again: very few lines of code and just about every line directly related to the task.