in reply to Re^11: Sorting names using Regular Expressions and placing them in different Files.
in thread Sorting names using Regular Expressions and placing them in different Files.

Kiran,

Here's what you want ..

#!/usr/bin/perl -w use strict; # Filter specific strings from an input file into specific # files. { # Open input and output files. open ( INPUT, '<', 'html_LogFiles' ) or die "Unable to open input file: $!"; open ( BSC, '>', 'BSC' ) or die "Unable to open BSC: $!"; open ( SBSCSubsystem, '>', 'BSC' ) or die "Unable to open SBSCSubsystem: $!"; open ( MCBTSSubsystem, '>', 'BSC' ) or die "Unable to open MCBTSSubsystem: $!"; # Process input lines into output files. Note that # an input line may match more than one pattern and # therefore may appear in more than one output # file. while(<INPUT>) { # This breaks the incoming line into the part before # the pattern, the pattern itself, and after the # pattern. We then output the last two parts, # followed by the last part. This effectively # truncates the first part. if ( /^(.+)(BSC-)(.+)$/ ) { print BSC "$2$3 $3\n"; } if ( /^(.+)(SBSCSubsystem-)(.+)$/ ) { print SBSCSubsystem "$2$3 $3\n"; } if ( /^(.+)(MCBTSSubsystem-)(.+)$/ ) { print MCBTSSubsystem "$2$3 $3\n"; } } # Close input and output files. close ( INPUT ); close ( BSC ); close ( SBSCSubsystem ); close ( MCBTSSubsystem ); }

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

  • Comment on Re^12: Sorting names using Regular Expressions and placing them in different Files.
  • Download Code