I'm assuming there will be no brackets in your code and all numbers will be positive integers, separated by operators or spaces.
Use a stack data structure. (In case you don't know what that is, it's a data structure with two operations called pop and push, you should read up about it if you have never heard of it before).
Whenever you read a digit, keep reading until you find a non-digit. All the digits you read now make up an integer. Push that integer onto the stack.
Repeat until you read an operator (+, -, *, /)
Once you read an operator, apply that operator to the last two values on the stack and push the result on the stack.
This is how math is done internally in compilers.
Once you have completed a line, check if there is only one value on the stack. If there isn't, it means there is a non-matching number of integers and operators in the instructions. If there is only one number, write it to the file.
EDIT: It's probably best if you create a new file for your output (and if necessary, rename that to the name of the input file at the end)
Then read each line from the input file and paste it and the result into the output file.