Ads by Google

Donate

If you like articles and you want an increase of them, please make a little donation. If you make a donation you can submit us by mail an argument for next articles!

Importo: 

add RSS

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati

Subscribe to Blog

Follow us on Twitter

follow us

Manfriday blog gadget

Perl
Find in file
Mercoledì 28 Gennaio 2009 19:56
Now we are going to see how it's simple to parse a file , looking for a specific pattern inside its rows.

with 4 lines of code you can find every want and print out the line with containing the pattern.

Inside the if statement we can use RegEx and make combo between more patterns.

#!/usr/local/bin/perl
use strict;
open (FI1, "<c:\\dump.log") or die "Can't open 'dump.log'";
while (<FI1>) {
if (/"(perlispowerful[a-zA-Z0-9]*)"/) {
print;
}
}
 
 
Watch dog
Mercoledì 28 Gennaio 2009 19:42
Perl is a powerful script language, it's very used in network and system administration.
infact it has a lot of functionalities about string, url, path management with the support of a good RegEx engine. 
 
This example could be very useful to monitor a FTP folder. So when a file is added you can start an other process on that file without any effort.
For example, here we will try to find new .tar.gz files in a directory every 5 seconds and lunch an other perl script on them.
 
Follow comments into the code. 

# $Dir is the directory to watch

unless ($Dir =~ /\\$/)
{
$Dir = $Dir."\\";
}

print "Watched directory: ".$Dir."\n";
 


Ricerca personalizzata