?
Solved

Certain position in Text files

Posted on 2003-03-16
8
Medium Priority
?
237 Views
Last Modified: 2006-11-17
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
Comment
Question by:WesleyWee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 1

Expert Comment

by:zerofill
ID: 8150262
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
 

Author Comment

by:WesleyWee
ID: 8150415
and if i only want a certain line from the BIN2?
0
 
LVL 1

Expert Comment

by:zerofill
ID: 8150474
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
Industry Leaders: 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!

 

Author Comment

by:WesleyWee
ID: 8152423
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
 
LVL 1

Accepted Solution

by:
zerofill earned 120 total points
ID: 8153832
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
 

Author Comment

by:WesleyWee
ID: 8162685
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
 
LVL 1

Expert Comment

by:zerofill
ID: 8165461
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
 

Author Comment

by:WesleyWee
ID: 8166998
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question