1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; printf "%s wird ", $_; if ( $_ =~ /^G1(.+?F30000)/ ) { printf "ersetzt durch %s\n", join ('', "G0", $1); } else { print "nicht ersetzt\n"; } } __DATA__ G1 Z0.500 F30000 G1 X13.379 Y-36.065 F30000 G1 Z0.100 F30000 G1 E76.00000 F300000 G1 X13.760 Y-35.411 E76.37759 F2400.000 G1 X14.123 Y-34.917 E76.68356 G1 X14.170 Y-34.656 E76.81576 G1 X14.133 Y-34.485 E76.90331 G1 X14.038 Y-34.357 E76.98253 G1 X13.947 Y-34.323 E77.03113 G1 X13.673 Y-34.283 E77.16949 G1 X13.078 Y-34.094 E77.48100 G1 X13.163 Y-33.464 E77.79807 G1 X13.321 Y-33.182 E77.95920
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#!/usr/bin/perl use strict; use warnings; my @array = <DATA>; foreach( @array ){ s/G1/G0/ if(m/F30000/); print $_; } __DATA__ G1 Z0.500 F30000 G1 X13.379 Y-36.065 F30000 G1 Z0.100 F30000 G1 E76.00000 F300000 G1 X13.760 Y-35.411 E76.37759 F2400.000 G1 X14.123 Y-34.917 E76.68356 G1 X14.170 Y-34.656 E76.81576 G1 X14.133 Y-34.485 E76.90331 G1 X14.038 Y-34.357 E76.98253 G1 X13.947 Y-34.323 E77.03113 G1 X13.673 Y-34.283 E77.16949 G1 X13.078 Y-34.094 E77.48100 G1 X13.163 Y-33.464 E77.79807 G1 X13.321 Y-33.182 E77.95920
$ perl -i.old -pE 's/^G1/G0/ if m/F30000/' ncfile.dat
$ perl -i.old -pE 's/^G1/G0/ if m/\bF30000\b/' ncfile.dat