"John W. Krahn" wrote: > > Chris Hurt wrote: > > > > Hi all; > > Hello, > > > Got a newbie question for you. I have a number of exactly 10 digits > > (2001090701) and I want to be able to read it from a file, cut the first 8 > > digits from the last two digits and put each into a variable (for comparison > > and addition). I would do it in the korn shell like this: > > > > NUM=`grep Serial FILE | awk '{print $1}'` > > TODAY=`date '+%Y%m%d'` > > FDAY=`echo $NUM | cut -c 1-8` > > typeset -Z2 INCR > > INCR=`echo $NUM | cut -c 9-10` > > if [ $FDAY -ne $TODAY ]; then > > SNUM="${TODAY}01" > > else > > let INCR="$INCR + 1" > > SNUM="${TODAY}${INCR}" > > fi > > print " $SNUM ;Serial" >> NEWFILE > > my ( $num, $snum ); > > open FILE, $file or die "Cannot open $file: $!": > /Serial/ and $num = (split)[0] and last while <FILE>; > close FILE; > > my @date = localtime; > my $today = sprintf '%04d%02d%02d', $date[5]+1900, $date[4]+1, $date[3]; > > my ( $fday, $incr ) = unpack 'a8 a2', $num; > if ( $fday == $today ) { > $snum = "${today}01"; > } > else { > $snum = sprintf '%s%02d', $today, ++$incr; > } > > open NEWFILE, ">> $newfile" or die "Cannot open $newfile: $!"; > print " $snum ;Serial"
Sorry, that should be: print NEWFILE " $snum ;Serial" John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]