#!/usr/bin/perl -w use strict; my %translation = ( char => 'VARCHAR2', varchar => 'VARCHAR2', decimal => 'NUMBER', integer => 'NUMBER', bigint => 'NUMBER', bit => 'NUMBER', tinyint => 'NUMBER', smallint => 'NUMBER', numeric => 'NUMBER', money => 'NUMBER', float => 'FLOAT', real => 'REAL', date => 'DATE', time => 'DATE', smalldatetime => 'DATE', datetime => 'DATE', timestamp => 'TIMESTAMP', longchar => 'CLOB', binary => 'BLOB', varbinary => 'BLOB', longbinary => 'LONG RAW', ); my %count; my $rx = qr/@{[join '|', map quotemeta, keys %translation ]}/; while (<>) { if(s/^\s*go\s*$/\/\n/gi) { $count{GO}++; print "TABLESPACE ARSAMS\n"; } s/\b($rx)\b/$count{$translation{$1}}++; $translation{$1}/egi; $count{total}++; print OUT; } print "$_: $count{$_} changes in this file" for sort keys %count;
This is untested code, but should work modulo typos. See Mark-Jason Dominus' excellent Program Repair Shop and Red Flags article series on Perl.com for introductory pointers on how to write better code.
Note that rather than try and open files itself, this script uses @ARGV for its input (so that Perl does error checking for us) and outputs to STDOUT which can be redirected (error checking by the shell). This is both lazy and flexible. Now you can say script file1 file2 file3 > outfile and get output just as requested.
Makeshifts last the longest.
In reply to Re: Matching Question #2
by Aristotle
in thread Matching Question #2
by curtisb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |