Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^12: Sorting names using Regular Expressions and placing them in different Files.

by talexb (Chancellor)
on Jan 09, 2007 at 14:23 UTC ( [id://593730]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found