Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

matches this but not all ...

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
Hi,

I'd like to find UserAccounts.txt and some other extensions,but reject all other .txt files.
My regex looks like:

unless (/.log|.nfo|.zip/ || $_ eq '.' || $_ eq '..' || $_ eq "UserAccounts.txt"){

but this will get in all other .txt files as well.
Any advise ?
Thanks


Long live king Moshiach !
 
Code:
[b]#!/usr/bin/perl[/b]

while (<DATA>) {
  chomp;
  print "$_\n" if $_ =~ /\.(nfo|log|zip)$/ || $_ eq 'UserAccounts.txt';
}

[blue]__DATA__
dummy.file
file.nfo
file123.log
anotherfile.nfo
not.me
nor.me
xyz.zip
abc123.txt
pickme.nfo
findme.zip
ignoreme.txt
UserAccounts.txt
dontpickme.txT
rubbish.file[/blue]

outputs:-

[red]file.nfo
file123.log
anotherfile.nfo
xyz.zip
pickme.nfo
findme.zip
UserAccounts.txt[/red]
 
Thanks,

almost ther,however I need all files NOT matching "nfo|log|zip" and ".txt" ,and to match also "UserAccounts.txt"


Long live king Moshiach !
 
Sorry MoshiachNow - I misunderstood you

How' this (it's too early for me to check it carefully - but I think it's o.k.)

Code:
[b]#!/usr/bin/perl[/b]

while (<DATA>) {
  chomp;
  print "$_\n" unless $_ =~ /\.(txt|nfo|log|zip)$/ ^ $_ eq 'UserAccounts.txt';
}

[blue]__DATA__
dummyfiletofind.file
ignore_me.nfo
file123ignore.log
ignoreanotherfile.nfo
yes.me
and.me
xyz_ignore_me.zip
abc123_not_me.txt
donotpickme.nfo
dontfindme.zip
pleaseignoreme.txt
UserAccounts.txt
pickme.txT
showme.file[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top