473,416 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Perl and print text file selectively help!

hey perl gurus!
i am new to this forum cause i need help. I have done many scripts.
but i want to use perl to do this:


What I want to do is this. I have a QRP file that I can convert to a txt file field separated by commas or not. I want to pring each line that has an actual date to the right of the word 'DATE:' if it doesnt have a date do not print that line.
Then the next thing i want my perl program to do is print each line that has
a numerical match. Print all fields in that line. What it is is a keyless entry
data file. People come into this gym i attend and it logs the date once for that day and then keeps track of each time someone uses the keyless entry. Shows the time and some words and then their mbr number and then their name. like this

--------------------------
Expand|Select|Wrap|Line Numbers
  1. Date: 01/07/2008
  2.  
  3. 3:45AM  1 Door One blah blah blah:  23 John Doe
  4. 4:45AM  1 Door One blah blah blah:  299 Jerry Doe
  5. 5:45AM  1 Door One blah blah blah:  223 Sissy Doe
  6.  
  7. Date: 01/08/2008
  8.  
  9. 3:45AM  1 Door One blah blah blah:  23 John Doe
  10. 4:45AM  1 Door One blah blah blah:  299 Jerry Doe
  11. 5:45AM  1 Door One blah blah blah:  223 Sissy Doe
  12. 7:45PM  1 Door One blah blah blah:  23 John Doe
what i want this program to do is to parse the text file and print an out put file
that is querried by their member number before their name and then gives
and out put like this: So the user puts in the member number of 23 and gets below text file. It searches entire file above.

Expand|Select|Wrap|Line Numbers
  1. Date: 01/07/2008
  2.  
  3. 3:45AM  1 Door One blah blah blah:  23 John Doe
  4.  
  5. Date: 01/08/2008
  6.  
  7. 3:45AM  1 Door One blah blah blah:  23 John Doe
  8. 7:45PM  1 Door One blah blah blah:  23 John Doe
pseudo code only.

read data.txt
print Date and actual date if date is to the right of the word Date:
(some lines with Date: do not have a date to the right; do not want to print nothing)
Print entire line that has member number that you are searching in only print
this entire line and go on to the next line searching for member number in that line and print that line tooo.
Do this until EOF.

can anyone help me I have a clue but need to get some good code.
I know you guys do it all the time and would appreicate your guidance.
or a great reference to doing this.

i have messed with code like in C++ but I would like to use perl to do this.
I think it can.

thanks

Robert ;)
Mar 10 '08 #1
3 2398
numberwhun
3,509 Expert Mod 2GB
Perl was made for text processing so to say you think you can should be more of an of course it can.

Why not produce some code and post it here (with the code tags as was mentioned by eWish) and then we will help you troubleshoot it if you get stuck.

Regards,

Jeff
Mar 10 '08 #2
i will try....
i will try....
i will try....
Mar 11 '08 #3
KevinADC
4,059 Expert 2GB
I would not normally post code unless you have tried to write some code first but I get the sense this is an honest request for help and the solution is pretty simple. Your file format is a bit vague, especially the blah blah blah part, but this may work:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. my $id = 23;
  4. open( my $data, 'path/to/QRPfile') or die "$!";
  5. while(<$data>){
  6.     print if (m#Date: \d\d/\d\d/\d\d\d\d#); # find the date
  7.     print if (m#:\s+$id[\s\S]+$#); # find the user id
  8. }
  9. close $data or die "$!";
  10.  
of course you may find that is very basic and you will want a data structure that is more useful, like a hash of the user id that stores the specifics of what the user did on any date, but we can cross that bridge later if you want to.
Mar 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Premshree Pillai | last post by:
Hello, I recently wrote a Perl version of pyAlbum.py -- a Python script to create an image album from a given directory -- plAlbum.pl . It made me realize how easy-to-use Python is. ...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
9
by: Gary | last post by:
I need to read a table from MySQL into a Perl script (already working) and then be able to print fields from the table selectively using a print button which is part of the HTML/CGI. Can someone...
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
66
by: happyse27 | last post by:
Hi All, my html code is sno 1) and perl code is sno 2). a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.