That's what i've tried (may be it is not the best approch);
Any way, My script doesn't work, it returns an error message (Use of uninitialized
value at formater.pl line 22, <INDATA> chunk 4.)
-----------------------------------------------------
#!/usr/local/bin/perl -w
$i=1;
$k=1;
open (INDATA, "<in_file.txt") || die("Can't open in file");
open (OUTDATA, ">out_file.txt") || die("Can't open out file");
while( $line = <INDATA> ) {
chomp;
@fields = split(",", $_);
for ($i = 0; $i < 400; $i++) {
if( $fields[$i]=~ /subject/ ) { $k=$i}
}
$line = join(":", $fields[0], $fields[2],$fields[$k], $fields[$k+1]);
print OUTDATA "$line\n";
}
close INDATA;
close OUDATA;
-------------------------------------------------------------------------------
Thanks ;
CHAFIK
----- Original Message -----
From: "Wiggins d Anconia"
Date: Tue, 29 Jun 2004 09:07:09 -0600
To: "mohammed chafik" , [EMAIL PROTECTED]
Subject: Re: Extracting fields from a data file
> > Hi all,
> >
> > I have input file like this:
> > ------------------------------------------------------------------------
> > header, 06-12-2004, path,
> /usr/bin/sh,attribute,100555,root,other,315,565690,
> subject,bscs,sgrp,9936,6785,0 0,return,success,0 (line1)
> >
> > header, 06-12-2004, path, /usr/bin/sh,attribute,100555,dba,5,
> subject,bscs,sgrp,9936,6785,0 ,return,success,0 (line2)
> >
> > header, 06-12-2004, path,
> /usr/bin/sh,attribute,100555,tom,other,315,56,11,54,77,10,88,
> subject,bscs,sgrp,9936,6785,0 0,return,success,0 (line3)
> > -----------------------------------------------------------------------
> >
> > I need to generate an output file like this (deleting fields between
> attribute and subject, please
> > note that number of those fields is variable):
> >
> -----------------------------------------------------------------------------------
> > header, 06-12-2004, path, /usr/bin/sh, subject,bscs,sgrp,9936,6785,0
> 0,return,success,0 (line1)
> >
> > header, 06-12-2004, path, /usr/bin/sh, subject,bscs,sgrp,9936,6785,0
> 0,return,success,0 (line 2)
> >
> > header, 06-12-2004, path, /usr/bin/sh, subject,bscs,sgrp,9936,6785,0
> 0,return,success,0 (line 3)
> >
> -----------------------------------------------------------------------------------
>
> What have you tried, where did you fail? Asking for free solutions
> isn't well looked upon...
>
> http://danconia.org
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>