Re: Extract same text from file.

From: Abhinav (matrix_calling_at_yahoo.dot.com)
Date: 08/16/04


Date: Mon, 16 Aug 2004 15:43:35 +0530

Ryan Keeling wrote:

> Hi
> I have the following text file which I want to use to populate text
> files containing data only relevant to a particular project. Is it
> possible for me to group similar lines together and put them in their
> own text file? Such as a file containing all entries for
> MS102_PCP.Implementation and another file for MS102_PCP.Support.
>
> Any help would be greatly appreciated!
>
>
> 2004:01:07:3:02:MS102_PCP:Belfast:Charge:PCP:Implementation:+:5.5
> 2004:01:07:3:02:MS102_PCP:Belfast:Charge:PCP:Support:+:2.0
> 2004:01:05:1:02:MS102_PCP:Belfast:Charge:PCP:Implementation:+:7.5
> 2004:01:09:5:02:MS102_PCP:Belfast:Charge:PCP:Meetings:+:1.0
> 2004:01:20:2:04:MS102_PCP:Belfast:Charge:PCP:Standards:6.5
> 2004:01:19:1:04:MS102_PCP:Belfast:Charge:PCP:Standard:7.5
> 2004:02:03:2:06:MS102_PCP:Belfast:Charge:PCP:Support:+:2.0
> 2004:03:02:2:10:MS102_PCP:Belfast:Charge:PCP:Implementation:+:5.5
> 2004:03:03:3:10:MS102_PCP:Belfast:Charge:PCP:Implementation:+:7.5
> 2004:03:02:2:10:MS102_PCP:Belfast:Charge:PCP:Support:+:2.5
> 2004:03:26:5:13:MS102_PCP:Belfast:Charge:PCP:Support:+:7.5
> 2004:03:29:1:14:MS102_PCP:Belfast:Charge:PCP:Support:+:8.0
> 2004:03:30:2:14:MS102_PCP:Belfast:Charge:PCP:Implementation:+:8.0
> 2004:01:05:1:02:MS102_PCP:Belfast:Charge:PCP:Project-Control:+:7.5
> 2004:01:06:2:02:MS102_PCP:Belfast:Charge:PCP:Meetings:+:2.0
> 2004:01:06:2:02:MS102_PCP:Belfast:Charge:PCP:Meetings:+:0.7
>

Something like this (untested) ?

use strict;
use warnings;

while (<STDIN>)
{
   my @outStr = split ':';
   system qq(echo '$_' >> '$outStr[9].txt');

}
Regards

--
Abhinav


Relevant Pages

  • Re: Why does glob() work in while loop?
    ... : use strict; ... : use warnings; ... because I didn't think that the while condition would populate ... This is explained in the documentation for the glob function. ...
    (comp.lang.perl.misc)
  • Re: Subroutine interaction
    ... >if it you pass it by reference to another function, and populate it ... >You're not filling the same hashes and arrays; ... I *did* use strict in my main script. ... Since the main script never saw the subroutines, its strict pragma did not notice my error. ...
    (perl.beginners)
  • Re: Extract same text from file.
    ... Ryan Keeling wrote: ... > I have the following text file which I want to use to populate text ... a filename from fields 8 and 9 to append the current line to. ...
    (comp.lang.perl.misc)
  • Re: Hangman
    ... The correct syntax to populate ... Example, j,l,u,v etc.so the user knows the letters they have ... Using warnings would have told you that. ...
    (comp.lang.perl.misc)
  • Re: Subroutine interaction
    ... you pass it by reference to another function, and populate it THERE. ... 'strict', ... [I'm looking for programming work. ...
    (perl.beginners)