472,983 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Perl Script for Parsing

Hi,

I am looking out for a Perl script to do the following. I am quite
positive someone must have written something similar.

- A perl script to open a directory/folder and access all files and
directories(and files within it)after a particular time stamp.

- Then for each file with a particular string in its name, access the
file and look for string
':20C::RELA//49879'

- Based upon that do throw an error or proceed for some other tasks.
I don't have the details yet from my manager, but I figure this script
will be run as a cron - every night.
I know PERL is pretty nifty for such tasks, that's why I feel
confident that someone must have written a script
already.

I did look at CPAN, but it is overwhelming. Still looking though.

Thanks,
- v796.
Jul 19 '05 #1
2 4978
v796 wrote:
I am looking out for a Perl script to do the following. I am quite
positive someone must have written something similar.

- A perl script to open a directory/folder
perldoc -f opendir
perldoc -f readdir
and access all files and directories
perldoc perlsyn (in particular the for and while loops)
perldoc -f open
(and files within it)
Ah, so you want it recursive? Why didn't you say so from the beginning?
Forget about opendir, readdir, while, and for, just use

perldoc File::Find
after a particular time stamp.
perldoc -f -M
- Then for each file with a particular string in its name,
perldoc -f index
access the
file and look for string
':20C::RELA//49879'
perldoc -f open
perldoc -f index
- Based upon that do throw an error or proceed for some other tasks. I did look at CPAN, but it is overwhelming. Still looking though.


Good idea, but including error checking this is probably 15-20 lines of code
max. I doubt that you will find something this simple on CPAN.

jue
Jul 19 '05 #2
> Good idea, but including error checking this is probably 15-20 lines of code
max. I doubt that you will find something this simple on CPAN.


Everybody writes this all the time. Today's implementation (untested):

#/usr/bin/perl
use strict;
use warnings;
use File::Find;

my $root_dir = '/etc';
my $time_stamp = time - 24 * 60 * 60; # last 24 hours
my $regex = qr':20C::RELA//49879'; # your regex
my @candidates;

find(
sub {

my $cur_file = $File::Find::name;
return unless -f $cur_file && (stat($cur_file))[9] >= $time_stamp;

# opportunity for improvement here: the error does not need to be fatal
open my $FILE, $cur_file or die "Cannot open file $cur_file\n";

READLINE: while (<$FILE>) {
push(@candidates, $cur_file), last READLINE if /$regex/;
}

},

$root_dir
);
{
local $, = "\n";
print @candidates;
}

__END__

Regards, Roel
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
52
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
1
by: Wet Basement | last post by:
I am passing data to a putcart.pl , parsing it, then building the query string to put the item in the shopping cart: $cartStr =...
3
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
0
by: Antwerp | last post by:
Hi, I'm trying to create a perl script that will log into a website (the login form uses POST), navigate to several pages, and append the (html) content parsed from those pages to a seperate log...
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
2
by: Gary42103 | last post by:
Hi I need Perl Script to do Data Parsing using existing data files. I have my existing data files in the following directory: Directory Name: workfs/ams Data File Names: 20070504.dat,...
3
by: sainiamit25 | last post by:
Hi, I am trying to set up environment for XML parsing using perl. I downloaded XML::Simple and installed it too. When i try to run my program, it says, you need to install parser. When i try to...
3
by: tundal45 | last post by:
Hey Guys, I am trying to automate the process of loading data in our oracle server. As a part of that process, I am working on a perl script that loads external tables from data files. What I am...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.