473,385 Members | 1,720 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,385 software developers and data experts.

search multiple files same extension.

Zuddie
4
Hi All,

I have to move my mail server, up to now I've been using catch all forwarding... Now I have to set up a separate account for each of the names I have been using over the years.

The task seems hopeless, unless I can come up with a way to search all of my Eudora in boxes (and I have a lot of them) for all mail sent to *@domain.com (where * is a wild card) I have used perl before, and I know it's the right application to use for this, but I'm a bit rusty. Can anyone out there help me get started?

Zuddie
Sep 2 '07 #1
8 2340
KevinADC
4,059 Expert 2GB
something like:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. @ARGV = <*.ext>;
  4. open (OUT, '>mailboxes.txt') or die "$!";
  5. while (<>) {
  6.    print OUT "$1\n" if (/(\S+@domain\.com)/);
  7. }
  8. close OUT;
Sep 2 '07 #2
Zuddie
4
Got the following errors:

Possible unintended interpolation of @domain in string at C:\Perl\getemailnames.pl line 6.
Global symbol "@domain" requires explicit package name at C:\Perl\getemailnames.pl line 6.
Execution of C:\Perl\getemailnames.pl aborted due to compilation errors.

I changed:

Expand|Select|Wrap|Line Numbers
  1. print OUT "$1\n" if (/(\S+@domain\.com)/);
to:

Expand|Select|Wrap|Line Numbers
  1. print OUT "$1\n" if (/(\S+\@domain\.com)/);

Then it ran, and the output was as expected... Thanks
Sep 2 '07 #3
numberwhun
3,509 Expert Mod 2GB
No worries. This is because the array @domain was not defined with my before first being used. Simply change the code to be like this:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. @ARGV = <*.ext>;
  5.  
  6. open (OUT, '>mailboxes.txt') or die "$!";
  7. my @domain;
  8.  
  9. while (<>) {
  10. print OUT "$1\n" if (/(\S+@domain\.com)/);
  11. }
  12.  
  13. close OUT;
  14.  
That should resolve that issue.

Regards,

Jeff
Sep 2 '07 #4
KevinADC
4,059 Expert 2GB
Actually, since he is searching for the literal string 'blah@domain.com' in the input files escaping the @ symbol is the correct thing to do. I should have had that in the code I posted, that was my mistake.
Sep 2 '07 #5
numberwhun
3,509 Expert Mod 2GB
He he, sorry about that. I though it was an array. Wasn't thinking. All day watching two kids will do that to you.

Regards,

Jeff
Sep 3 '07 #6
Zuddie
4
Another useful modification would be to eliminate all text before the word just ahead of the @ symbol. For example if there is a space coma quote colon or equal sign before the name (blah blah:cooldude@domain.com blah blah), it would be nice to get only cooldude@domain.com and not the text ahead or following.

I'm thinking something along the lines of:

^(.*)([\s\,\"\;\:\=])(.*)(/(\S+\@domain\.com)/)(.*)

But I don't have the complete thought.
Sep 3 '07 #7
KevinADC
4,059 Expert 2GB
a simpler approach:

/([\w-]+\@domain\.com)/

The character class \w is: 'a-zA-Z0-9_' and I added a dash '-' which I think is legal for email addresses. So if you have:

joe blow:joe-blow@foo.com

it will return:

joe-blow@foo.com

There is probably a module for parsing email address out of text/files.
Sep 3 '07 #8
Zuddie
4
So the final version looks like this:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. @ARGV = <*.mbx>;
  4. open (OUT, '>mailboxes.txt') or die "$!";
  5. while (<>) {
  6.     print OUT "$1\n" if (/([\w-]+\@domain\.com)/);
  7. }
  8. close OUT;
And it works... Thanks.

Yah you're probably right, there could be a module, but getting regular expressions right is so rewarding.
Sep 3 '07 #9

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

Similar topics

6
by: John Doe | last post by:
I realise that this is not really a python question, but python's the only language I'd be comfortable trying to deal with this. What I need is to search a drive and find all the AVI format files...
8
by: Stromboli | last post by:
Hi, I have my site available in a couple of languages most of the files are indexf.html (french), indexi.html (italian) and indexde.html (german).. I'd like to start using multiviews but I've...
1
by: Prem | last post by:
Hi, I need to search a particular directory for all the files that do not have any extension and have a specific naming convension. The first 3 characters of the file name are alpha and the rest...
2
by: John Smith | last post by:
Hello all: I am trying to search for more than one extension in a directory at the same time with the following code: string files = Directory.GetFiles(sDir, "*.doc*.dot"); However, this...
2
by: Alphonse Giambrone | last post by:
Is there a way to use multiple search patterns when calling Directory.GetFiles. For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all files with the aspx extension. But what if...
0
by: EC | last post by:
There are times when I use the Search utility of windows explorer to find ASPX file(s) that contains a specific word. The Search utility however skips the <script ..> </script> block in the ASPX...
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
0
by: tanish2k | last post by:
hi. I am using c#, visual studio 2003. I need to validate a xml file against schema which itself has 2 more schema imported under it. i have following 2 xsd files : xsd1 --->...
3
by: =?Utf-8?B?UGVycmlud29sZg==?= | last post by:
Not sure where to post this... Found some interesting behavior in Windows Search (Start =Search =All files and folders =search for "A word or phrase in the file:"). This applies to XP and maybe...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.