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

pattern search

36
Hi can some one help with my problem

i have a script which search for the files in the directory and download it to our directroy and it has sleep to repeat the process againg after 1 hour.it compares the file in source directory , if it is not there then down load it our directory

all the comparision i am doing by grep /^$newFiles[$file2verify]/, @{$destifiles[0]}

but grep is failing when it find the following files
1)New Text Document.txt
2)New Text Document (3).txt

it is dowanloading New Text Document (3).txt for every iterations though it is already downloaded .

my guess is it failing because of (3)in the file name

can any one help me to over come this...


thanking in advance

kiran
Mar 26 '08 #1
8 1333
nithinpes
410 Expert 256MB
To avoid special meaning of parentheses when used as a pattern, you need to escape it with backslash . In this case, $newFiles[$file2verify] should be:
Expand|Select|Wrap|Line Numbers
  1. $newFiles[$file2verify]='New Text Document \(3\).txt' ;
  2.  
Mar 26 '08 #2
jain236
36
To avoid special meaning of parentheses when used as a pattern, you need to escape it with backslash . In this case, $newFiles[$file2verify] should be:
Expand|Select|Wrap|Line Numbers
  1. $newFiles[$file2verify]='New Text Document \(3\).txt' ;
  2.  
Hi Thank you for your reply

actually $newFiles[$file2verify] is getting dynamically.it reads from a dynamic array.so is there any othe way ?
Mar 26 '08 #3
nithinpes
410 Expert 256MB
Hi Thank you for your reply

actually $newFiles[$file2verify] is getting dynamically.it reads from a dynamic array.so is there any othe way ?
Change this :
Expand|Select|Wrap|Line Numbers
  1. grep /^$newFiles[$file2verify]/, @{$destifiles[0]}
  2.  
to:
Expand|Select|Wrap|Line Numbers
  1. grep /^\Q$newFiles[$file2verify]\E/, @{$destifiles[0]}
  2.  
the variable between \Q and \E will be interpolated literally without considering any wildcards/special variables used for regular expression.
Mar 26 '08 #4
jain236
36
Change this :
Expand|Select|Wrap|Line Numbers
  1. grep /^$newFiles[$file2verify]/, @{$destifiles[0]}
  2.  
to:
Expand|Select|Wrap|Line Numbers
  1. grep /^\Q$newFiles[$file2verify]\E/, @{$destifiles[0]}
  2.  
the variable between \Q and \E will be interpolated literally without considering any wildcards/special variables used for regular expression.
Hi nithinpes
thankyou for you reply

but i tried it is not working ..here is my code which i am try to do..
Expand|Select|Wrap|Line Numbers
  1. if(@invalidfiles)
  2.         {
  3.             my @updatedfiles;
  4.             foreach my $invfile(@srcFiles)
  5.             {
  6.  
  7.                 if(grep !/\Q^$invfile\E/, @invalidfiles )
  8.                 {
  9.                     #logMsg("New file $invfile Found");
  10.                     push (@updatedfiles,$invfile);
  11.  
  12.                 }
  13.             }if(@invalidfiles)
  14.         {
  15.             my @updatedfiles;
  16.             foreach my $invfile(@srcFiles)
  17.             {
  18.  
  19.                 if(grep !/\Q^$invfile\E/, @invalidfiles )
  20.                 {
  21.                     #logMsg("New file $invfile Found");
  22.                     push (@updatedfiles,$invfile);
  23.  
  24.                 }
  25.             }
  26.  
above both @invalidfiles, and @src files contains same files
[0] =download_.html
[1] = newtextdocument .txt
[2]= lates.txt
[3] = New Microsoft Excel Worksheet.xls

etc

what i am trying to do in the above code is..
i reading from a directory ,downloading it and then adding it to invalid files to avoid repeaative downloading of the same file by comparing the files.
as per your instruction it the \Q \E.

when there is no new files added in the source files...it should not add files in updatedfile, but it is happening and adding all the files in updatedfile

your help will be appreciated
Mar 27 '08 #5
nithinpes
410 Expert 256MB
Hi nithinpes
thankyou for you reply

but i tried it is not working ..here is my code which i am try to do..
Expand|Select|Wrap|Line Numbers
  1. if(@invalidfiles)
  2.         {
  3.             my @updatedfiles;
  4.             foreach my $invfile(@srcFiles)
  5.             {
  6.  
  7.                 if(grep !/\Q^$invfile\E/, @invalidfiles )
  8.                 {
  9.                     #logMsg("New file $invfile Found");
  10.                     push (@updatedfiles,$invfile);
  11.  
  12.                 }
  13.             }if(@invalidfiles)
  14.         {
  15.             my @updatedfiles;
  16.             foreach my $invfile(@srcFiles)
  17.             {
  18.  
  19.                 if(grep !/\Q^$invfile\E/, @invalidfiles )
  20.                 {
  21.                     #logMsg("New file $invfile Found");
  22.                     push (@updatedfiles,$invfile);
  23.  
  24.                 }
  25.             }
  26.  
above both @invalidfiles, and @src files contains same files
[0] =download_.html
[1] = newtextdocument .txt
[2]= lates.txt
[3] = New Microsoft Excel Worksheet.xls

etc

what i am trying to do in the above code is..
i reading from a directory ,downloading it and then adding it to invalid files to avoid repeaative downloading of the same file by comparing the files.
as per your instruction it the \Q \E.

when there is no new files added in the source files...it should not add files in updatedfile, but it is happening and adding all the files in updatedfile

your help will be appreciated

Kiran,
The caret symbol should be outside \Q, observe the pattern that I posted carefully. If you use it after \Q, it would lose its meaning of beginning of line.It will be matched to actual caret(^) symbol.e.g the line:
Expand|Select|Wrap|Line Numbers
  1. if(grep !/\Q^$invfile\E/, @invalidfiles )
  2.  
should be:

Expand|Select|Wrap|Line Numbers
  1. if(grep !/^\Q$invfile\E/, @invalidfiles )
  2.  
Mar 27 '08 #6
jain236
36
Kiran,
The caret symbol should be outside \Q, observe the pattern that I posted carefully. If you use it after \Q, it would lose its meaning of beginning of line.It will be matched to actual caret(^) symbol.e.g the line:
Expand|Select|Wrap|Line Numbers
  1. if(grep !/\Q^$invfile\E/, @invalidfiles )
  2.  
should be:

Expand|Select|Wrap|Line Numbers
  1. if(grep !/^\Q$invfile\E/, @invalidfiles )
  2.  
hi nithin..

i tried both ways.. but still it is going inside the loop though i mentioned !
Mar 27 '08 #7
nithinpes
410 Expert 256MB
hi nithin..

i tried both ways.. but still it is going inside the loop though i mentioned !
I missed out one thing.The line:
Expand|Select|Wrap|Line Numbers
  1. if(grep !/^\Q$invfile\E/, @invalidfiles )
  2.  
Using ! before / is not the right-way to use for negative search. Change that to:
Expand|Select|Wrap|Line Numbers
  1. if(!(grep /^\Q$invfile\E/, @invalidfiles) )
  2.  
Mar 27 '08 #8
jain236
36
I missed out one thing.The line:
Expand|Select|Wrap|Line Numbers
  1. if(grep !/^\Q$invfile\E/, @invalidfiles )
  2.  
Using ! before / is not the right-way to use for negative search. Change that to:
Expand|Select|Wrap|Line Numbers
  1. if(!(grep /^\Q$invfile\E/, @invalidfiles) )
  2.  
Wow ! its working dear..

thanks a lot....for your help.....
thank you so much
Mar 27 '08 #9

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

Similar topics

1
by: Dariusz | last post by:
Despite looking at a number of tutorials in books and online examples on pattern matching - I can't quite get my head around it to work... so need some help. What I have now is a variable that...
2
by: BalyanM | last post by:
Hi, I am new to python.I am using it on redhat linux 9. I am interested to run python on a sun machine(SunE420R,os=solaris) with 4 cpu's for a pattern discovery/search program on biological...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
2
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search...
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...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
1
by: Eric | last post by:
I use RegEx to search pattern. Script works fine in the situation when there is a colon after each word and it fetch the rest of the word from that line. Now the pattern is in square bracket and i...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
3
by: mercuryshipzz | last post by:
#!/usr/bin/perl #use strict; use warnings; sub search_pattern { my $file_name = $_;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.