Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I want to search through an asci file

Posted on 2000-03-14
4
Medium Priority
?
206 Views
Last Modified: 2010-03-05
I'm a new programmer in Perl. I have a ascii file with 20000 records. How i can make searches inside this file with one or two fields. Which are the steps?
May i have a simple example of this type of program.
Thank you
0
Comment
Question by:vage78
[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
  • 3
4 Comments
 
LVL 5

Expert Comment

by:PC_User321
ID: 2615128
Is each line of the file divided into fields?
If so, what is used to separate the fields?

Here is an example where the fields are separated with a '|' character.
Assume you want the first field to be "Person" and the third field to be "Every month":

$Record0Search = "Person";
$Record2Search = "Every month";

open(FILE, "data.txt");
while ($Line = <FILE>) {
   @Fields = split '\|', $Line;
   print $Line if (($Fields[0] eq $Record0Search) && ($Fields[2] eq $Record2Search));
}

0
 
LVL 5

Accepted Solution

by:
PC_User321 earned 90 total points
ID: 2615182
The 'split' command divides the lines into fields, separated by the character within the single quotes.

The 'eq' in the comparison means that the fields must be exactly equal the the values you are looking for.  Other comparisons are possible, such a case-insentive comparisons, or checking to see if the field _contains_ the string you are searching for.
http://www.perl.com/pub/doc/manual/html/pod/perlre.html gives you details.
For example, if you just wanted to find lines containing words "seven" or "eight" (case insensitive) in any field you would replace the print line with
   print $Line if ($Line =~ /seven|eight/i/);
(and you would not need to do the 'split')

I hope this helps.
0
 

Author Comment

by:vage78
ID: 2615208
Thank you very much.I will try.My file is very big. Is this a problem? (20000 records) or everything is ok.
May i use also indexes.
Thanks a lot
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2615210
>> My file is very big. Is this a problem?  No

>> May i use also indexes?
Please explain what you mean.

0

Featured Post

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!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

661 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