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 31
#!/bin/perl use strict; use warnings; my $filename = '808.nc'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $g="G"; my $f="F"; while (my $row = <$fh>) { chomp $row; my @words = split / /, $row; foreach (@words){ my $Word=$_; my $char=substr($_, 0, 1); if ($char eq "G"){ if($Word ne $g){ $g=$Word; print "$Word " } } elsif ($char eq "F"){ if($Word ne $f){ $f=$Word; print "$Word " } } else {print "$Word "} } print "\n"; }
1
2
3
4
5
6
7
8
9
N46 G1 X13 Y-18 Z-2 F2328
N48 G3 Z0 X15 Y-18 I0 K2 F2328
N49 G0 X15 Y-18 Z15
N51 (Planen2)
N52 G0 X10.102 Y-25.75
N53 G0 X10.102 Y-25.75 Z15
N54 G0 X10.102 Y-25.75 Z5
N55 G1 X10.102 Y-25.75 Z1 F2328
N57 G2 Z-1 X8.102 Y-25.75 I-2 K0 F2328
1
2
3
4
5
6
7
8
9
N46 G1 X13 Y-18 Z-2 F2328
N48 G3 Z0 X15 Y-18 I0 K2
49 G0 X15 Y-18 Z15
51 (Planen2)
52 X10.102 Y-25.75
53 X10.102 Y-25.75 Z15
54 X10.102 Y-25.75 Z5
N55 G1 X10.102 Y-25.75 Z1
N57 G2 Z-1 X8.102 Y-25.75 I-2 K0
1
2
3
4
5
6
7
8
9
N46 G1 X13 Y-18 Z-2 F2328
N48 G3 Z0 X15 Y-18 I0 K2 F2328
N49 G0 X15 Y-18 Z15
N51 (Planen2)
N52 G0 X10.102 Y-25.75
N53 G0 X10.102 Y-25.75 Z15
N54 G0 X10.102 Y-25.75 Z5
N55 G1 X10.102 Y-25.75 Z1 F2328
N57 G2 Z-1 X8.102 Y-25.75 I-2 K0 F2328
1
2
3
4
5
6
7
8
9
N46 G1 X13 Y-18 Z-2 F2328
N48 G3 Z0 X15 Y-18 I0 K2
N49 G0 X15 Y-18 Z15
N51 (Planen2)
N52 X10.102 Y-25.75
N53 X10.102 Y-25.75 Z15
N54 X10.102 Y-25.75 Z5
N55 G1 X10.102 Y-25.75 Z1
N57 G2 Z-1 X8.102 Y-25.75 I-2 K0
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 31 32 33 34 35 36
#!/bin/perl use strict; use warnings; my $filename = '808.nc'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $g="G"; my $f="F"; while (my $row = <$fh>) { $row =~ s/\r?\n$//; my @words = split / /, $row; foreach (@words){ my $Word=$_; my $char=substr($_, 0, 1); if ($char eq "N"){ print "$Word" } elsif ($char eq "G"){ if($Word ne $g){ $g=$Word; print " $Word" } } elsif ($char eq "F"){ if($Word ne $f){ $f=$Word; print " $Word" } } else {print " $Word"} } print "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/perl use v5.18; use warnings; my ($g, $f) = ('G', 'F'); my $filename = '808.nc'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { $row =~ s/\r?\n$//; for my $word (split / /, $row){ say ''; given (substr($word, 0, 1)) { when ('N') { } when ('G') { if ($word ne $g) { $g = $word } else { next } } when ('F') { if ($word ne $f) { $f = $word } else { next } } } print " $word"; } }
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
#!/bin/perl use v5.18; use warnings; my ($g, $f) = ('G', 'F'); my $filename = '1001.nc'; if ($ARGV[0]){$filename=$ARGV[0];} my $arg1 = 0; if ($ARGV[1]){$arg1=$ARGV[1];} open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { $row =~ s/\r?\n$//; my $newrow; for my $word (split / /, $row){ # say ''; given (substr($word, 0, 1)) { when ('N') { if ($arg1 == 1) {next} } when ('G') { if ($word ne $g) { $g = $word } else { next } } when ('F') { if ($word ne $f) { $f = $word } else { next } } } $newrow=$newrow. " $word"; } $newrow=~ s/^\s+|\s+$//g; $newrow=$newrow."\n"; print $newrow; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/bin/perl use v5.18; use warnings; my $filename = shift // '1001.nc'; my $arg1 = shift // 0; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my ($g, $f) = ('G', 'F'); while (my $row = <$fh>) { $row =~ s/\r?\n$//; my $newrow; for my $word (split / /, $row){ given (substr($word, 0, 1)) { when ('N') { next if $arg1 == 1 } when ('G') { if ($word ne $g) { $g = $word } else { next } } when ('F') { if ($word ne $f) { $f = $word } else { next } } } $newrow .= " $word"; } $newrow =~ s/^\s+|\s+$//g; say $newrow; }