title: Edit G code Line by Line
body: <p>I want to read a g code file line by line, and based off of a comment at the end, do an action to it. The g code is coming out of Slic3r. Some example lines in no particular order look like this:</p>
  
  <pre><code>G1 Z0.242 F7800.000 ; move to next layer (0)
  G1 E-2.00000 F2400.00000 ; retract
  G1 X0.000 Y30.140 F7800.000 ; move to first skirt point
  G1 E0.00000 F2400.00000 ; unretract
  G1 X-53.493 Y30.140 E2.14998 F1800.000 ; skirt
  G1 X57.279 Y-37.776 E22.65617 ; perimeter
  G1 X-52.771 Y-38.586 E56.83128 ; infill
  </code></pre>
  
  <p>The comment always starts with a semicolon and also uses consistent terms, such as perimeter or infill. Ideally the script would read the line, search for the particular comment case, perform an action based on that, then update the file, and then go to the next line. I am somewhat new to python, so I know that this would be done with a for-loop with nested if statements, however I am not sure how to set up the architecture to be based of those key terms.</p>