And here's split.pl#!/usr/bin/perl -w use strict; use vars qw( $filename ); ($filename = shift) or die "Usage: $0 filename\n"; open(FIN,"$filename") or die "$0 : cannot read file \"$filename\"\n"; # assume it is a text file while(<FIN>) { } print sprintf("%8s",$.) , " $filename\n"; close(FIN); exit;
I assumed these would be text files, not binary, and I kept Getopt out of it on purpose.#!/usr/bin/perl -w use strict; use vars qw( $linect $filename $prefix $i $postfix ); ($linect = shift) or die "Usage: $0 lines_out filename new_name \n"; $linect = int($linect); if ($linect < 1) { print STDERR "$0 : cannot split less than 1 lines\n"; exit; } ($filename = shift) or die "Usage: $0 lines_out filename new_name \n"; ($prefix = shift) or die "Usage: $0 lines_out filename new_name \n"; $i = 0; $postfix = sprintf("%02d",$i); open(FIN,"$filename") or die "$0 : cannot read file \"$filename\"\n"; open(FOUT,">$prefix.$postfix") or die "$0 : cannot write file \"$prefi +x.$postfix\"\n"; # assume it is a text file while(<FIN>) { print FOUT $_ ; if (($. % $linect) == 0) { close(FOUT); $i++; $postfix = sprintf("%02d",$i); open(FOUT,">$prefix.$postfix") or die "$0 : cannot write file +\"$prefix.$postfix\"\n"; } } close(FIN); exit;
In reply to mimicing wc and split by dwhite20899
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |