• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Certain position in Text files

If i have file(text file) readable by notepad.
there are informations that i need from the file.

http://www.geocities.com/wwyz83/code.zip
*In the *ZIP file, the file *L1.UMC. i need the number of BIN2 table.
How do i get the data from the file?
0
WesleyWee
Asked:
WesleyWee
  • 4
  • 4
1 Solution
 
zerofillCommented:
open (FILE, "UMC/KC922L1.UMC") or die $!;
while (<FILE>)
{
     if ($_ =~ /\.UMC/)
     {
     ($empty, $MAPPING, $WAFER_ID, $BIN1, $BIN2, $BIN3, $BIN4)= split (/\s+/, $_);
     print "$BIN2\n";
     }
     
}
close (FILE);
0
 
WesleyWeeAuthor Commented:
and if i only want a certain line from the BIN2?
0
 
zerofillCommented:
open (FILE, "UMC/KC922L1.UMC") or die $!;
while (<FILE>)
{
    if ($_ =~ /\.UMC/)
    {
    ($empty, $MAPPING, $WAFER_ID, $BIN1, $BIN2, $BIN3, $BIN4)= split (/\s+/, $_);

   
if ($MAPPING eq 'myfilename') {print "$BIN2\n";}
#or whatever field you put (MAPPING, WAFER_ID ...)

    }
   
}
close (FILE);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
WesleyWeeAuthor Commented:
i'm sorry i didn't mean the columme i meant like the line.

it's cos that i need the total of BIN2 from each file and compare it with the summary (*L1.UMC).

that's why i asked you of how to get from a file so being able to count the number of BIN2 (the counting in my current code) and check it number of BIN2 in the summary file (*L1.UMC).
0
 
zerofillCommented:
open (FILE, "UMC/KC922L1.UMC") or die $!;
while (<FILE>)
{
   if ($_ =~ /\.UMC/) #this filters lines that contain *.UMC
   {
   ($empty, $MAPPING, $WAFER_ID, $BIN1, $BIN2, $BIN3, $BIN4)= split (/\s+/, $_); #this splits the current line into separate values (coloumns). The value of current line is in $_ variable
#You may put a counter here to do the sum:
$count+=$BIN2;
   }
   if ($_ =~ /TOTAL/) #gets the line containing "total"
   {
   ($empty, $TOTAL_STRING, $BIN1_TOTAL, $BIN2_TOTAL, $BIN3_TOTAL, $BIN4_TOTAL)= split (/\s+/, $_); #splits the total values and now you have the total of each coloumn. The total of BIN2 is stored in variable named $BIN2_TOTAL
   }
}
close (FILE);

#here you may compare the two values:

if ($count eq $BIN2_TOTAL){print "values are equal";}
else {print "Values are not equal";}


I hope you understand now
0
 
WesleyWeeAuthor Commented:
Hey thanks alot I've put my code all together already... thanks man!!!

*one last thing is when Opening the FILE. You stil remember my zip file right. I have combined 2 3 parts into one.

#!/usr/bin/perl

$some_dir= shift;

if($some_dir)
{
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
@files = grep {-f "$some_dir/$_" } readdir(DIR);
$number = 1;

#-================================================================
#-===To open *L1.UMC file to get total============================
#-================================================================
open (FILE, "UMC/KC922L1.UMC") or die $!;
while (<FILE>)
{
     if ($_ =~ /\.UMC/) #this filters lines that contain *.UMC
     {
          ($empty, $MAPPING, $WAFER_ID, $BIN1, $BIN2, $BIN3, $BIN4)= split (/\s+/, $_);
          #this splits the current line into separate values (coloumns).
          #The value of current line is in $_ variable
          #You may put a counter here to do the sum:

          $countL1+=$BIN2;
#          print "$countL1\n";

     }
     if ($_ =~ /TOTAL/) #gets the line containing "total"
     {
          ($empty, $TOTAL_STRING, $BIN1_TOTAL, $BIN2_TOTAL, $BIN3_TOTAL, $BIN4_TOTAL)= split (/\s+/, $_);
          #splits the total values and now you have the total of each coloumn.
          #The total of BIN2 is stored in variable named $BIN2_TOTAL
     }
}
close (FILE);

#-================================================================
#-===To open all UMC files and count Bin2s========================
#-================================================================
for( @files )
{
     unless ($line = /^.+\.UMC$/){next;} #process all *UMC
     if($line = /^.+L1\.UMC$/){next;} #ignore all **L1.UMC

     print "\n($number) $_=-";
     open F,"<$some_dir/$_" or warn "can't open $some_dir/$_: $!";
     $count = 0;
     $counter = 0;
     while( <F> )
     {
#          print;
          $counter++;
          if ($counter<=4){next;}
          $count += tr/2//;          
     }
     $ALL += $count;
     $number++;
     print ">Number of bin2: $count [Total: $ALL]\n";
}

#-================================================================
#-===To compare the total BIN2s using TOTAL amount================
#-================================================================
if ($ALL eq $BIN2_TOTAL){print "\n\n     --==Total values are equal==--\n\n";}
else {print "\n\n      --==ALL Values are not equal==--\n\n";}
}else{print "\n-=Please write a path name after the code=-\n\n";}



I'll like to make the <<open (FILE, "UMC/KC922L1.UMC") or die $!;>> to seek any file with the filename *.L1.UMC. As each time i run my code. the folder holding the *.UMC files. will only hold one *L1.UMC file. How is it done?
0
 
zerofillCommented:
for( @files )
{
 if($line = /^.+L1\.UMC$/){$L1_FILE=$_} #you have the name of the file stored in $L1_FILE
}

After that do:
open (FILE, "$L1_FILE") or die $!;
instead of:
open (FILE, "UMC/KC922L1.UMC") or die $!;

0
 
WesleyWeeAuthor Commented:
I kinda re-arranaged it to

#!/usr/bin/perl

$some_dir= shift;

if($some_dir)
{
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
@files = grep {-f "$some_dir/$_" } readdir(DIR);
$number = 1;

for( @files )
{
if($line = /^.+L1\.UMC$/){$L1_FILE=$_;}

#open (FILE, "UMC/KC922L1.UMC") or die $!;
open (FILE, "$L1_FILE") or die $!;
while (<FILE>)
{
     if ($_ =~ /\.UMC/) #this filters lines that contain *.UMC
     {
          ($empty, $MAPPING, $WAFER_ID, $BIN1, $BIN2, $BIN3, $BIN4)= split (/\s+/, $_);

          $countL1+=$BIN2;
     }
     if ($_ =~ /TOTAL/) #gets the line containing "total"
     {
          ($empty, $TOTAL_STRING, $BIN1_TOTAL, $BIN2_TOTAL, $BIN3_TOTAL, $BIN4_TOTAL)= split (/\s+/, $_);
          #splits the total values and now you have the total of each coloumn.
          #The total of BIN2 is stored in variable named $BIN2_TOTAL
     }
}
close (FILE);

#-================================================================
#-===To open all UMC files and count Bin2s========================
#-================================================================
     unless ($line = /^.+\.UMC$/){next;} #process all *UMC
     if($line = /^.+L1\.UMC$/){next;} #ignore all **L1.UMC

     print "\n($number) $_=-";
     open F,"<$some_dir/$_" or warn "can't open $some_dir/$_: $!";
     $count = 0;
     $counter = 0;
     while( <F> )
     {
#          print; #will bring the whole map onto screen
          $counter++;
          if ($counter<=4){next;}
          $count += tr/2//;          
     }
     $ALL += $count;
     $number++;
     print ">Number of bin2: $count [Total: $ALL]\n";
}

#-================================================================
#-===To compare the total BIN2s using TOTAL amount================
#-================================================================
if ($ALL eq $BIN2_TOTAL){print "\n\n     --==Total values are equal==--\n\n";}
else {print "\n\n      --==ALL Values are not equal==--\n\n";}
}else{print "\n-=Please write a path name after the code=-\n\n";}


#-================================================================
#-===To open *L1.UMC file to get total============================
#-================================================================


after running it i keep getting an error
"Died .... on line 16" - the line is at "open (FILE, "$L1_FILE") or die $!;"

-----------------------------------------------
for( @files )
{
if($line = /^.+L1\.UMC$/){$L1_FILE=$_;}

#open (FILE, "UMC/KC922L1.UMC") or die $!;
open (FILE, "$L1_FILE") or die $!;
while (<FILE>)
.
.
.
------------------------------------------------
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now