Re: how to change this code into perl
by kcott (Archbishop) on Aug 30, 2015 at 07:04 UTC
|
| [reply] [d/l] [select] |
|
|
Wow, nice! I thought this wouldn't work, but it turns out that a2p seems to handle it correctly, even with the FNR variable, and even gives not too ugly code,
I guess I just had disappointments with s2p, which doesn't even know about the gsed extension of semicolons working as statement separators.
| [reply] |
Re: how to change this code into perl
by BrowserUk (Patriarch) on Aug 30, 2015 at 06:56 UTC
|
perl -anle"next unless @L; print if $L[0] eq $F[0]; @L = @F;" in.txt >
+ out.txt
| [reply] [d/l] |
|
|
perl -anle"next unless @L; print if $L[0] eq $F[0]; @L = @F;" in.txt >
+ out.txt
will never enter into the loop because the next statement at the beginning will prevent @L from ever being set.
Perhaps this instead:
perl -anwle 'BEGIN{$L = "";} print if $F[0] eq $L; $L = $F[0];' in.tx
+t > out.txt
Although the BEGIN block isn't really necessary if the warnings are not activated:
perl -anle 'print if $F[0] eq $L; $L = $F[0];' in.txt > out.txt
| [reply] [d/l] [select] |
|
|
perl -anle"@L = @F, next if $. == 1; print if $L[0] eq $F[0]; @L = @F;
+" in.txt > out.txt
| [reply] [d/l] |
|
|
|
|
|
|
1 twenty
2 thirty
1 forty
1 fifty
output
1 twenty
1 forty
1 fifty
is there a way to script it instead of a oneliner. Thank you guys | [reply] [d/l] [select] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|