Adding or Removing line numbers to G Code files

More
14 Mar 2012 17:14 #18601 by ArcEye
Hi

Prompted by a discussion in another thread i thought I would publish my solution to this.

There are quite a few good CAM programs and code generators which insist upon having linenumbers at every line.

LinucCNC will run them, but they are completely superfluous and often very confusing.

The below will strip them or add them, note the different invocations for the 2 commands.
#!/bin/bash

## inserts or removes line numbers at start of each line
## usage: linenumbers insert oldfile newfile
##        linenumbers remove filename  (overwrites so perform on a copy)

case $1 in
    insert )    exec < $2
                d="N"
                e=" "
                a=1

                while read LINE ; do
                    c=$d$a$e$LINE
                    echo $c >> $3
                    ((a++))
                done ;;
    
    remove )    sed -i "s/^ *N[0-9]* //g" $2 ;;
esac

exit 0

enjoy

Please Log in or Create an account to join the conversation.

Time to create page: 0.052 seconds
Powered by Kunena Forum