The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find a string inside files yoavbe Shell Programming and Scripting 12 05-05-2008 01:19 PM
How to delete Directory and inside files using Find command bmkreddy SUN Solaris 3 07-10-2007 02:35 PM
how to find an errored disk raj.soladm SUN Solaris 2 08-28-2006 01:31 PM
how to find Script file location inside script asami Shell Programming and Scripting 10 03-15-2006 12:57 AM
Find files in Directories steiner Shell Programming and Scripting 4 04-02-2005 12:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2008
osramos osramos is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Need script to find errored files inside directories

Hi people.

I working on a script to check for files that they are suposed not to be on the directory. I mean, inside of each directory it must have some files but some could be wrong, and i want to move the files that are wrong.

Ex:
CSPOTGET edpst/CargadoresSPOT Historicos_Spot_MDI.zip
COBGET edpst/CargadorOmelBroker ??????.xls
CORGET edpst/CargadorOmelReuters CarOmlReuts.xls

On folder " edpst/CargadoresSPOT " must only have " Historicos_Spot_MDI.zip"

On folder " edpst/CargadorOmelBroker " must only have files with " yymmdd.xls" , and no others.

I imagine this "configuration" file where the 1st column is a variable, the second is the directory and the 3rd column is the file(s) of each directory.

Did you understand what i'm wrote?

osramos
  #2 (permalink)  
Old 09-22-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
You want to find files that DO NOT match the pattern, correct?
ksh allows you to do that:
Code:
#!/bin/ksh
# files that are not named Historicos_Spot_MDI.zip
ls edpst/CargadoresSPOT/!(Historicos_Spot_MDI.zip)
# 
ls edpst/CargadorOmelBroker/!(??????.xls)
#
ls edpst/CargadorOmelReuters/!(CarOmlReuts.xls)
  #3 (permalink)  
Old 09-22-2008
osramos osramos is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Ok, it works.

But there are almost 50 directories, with some of them with 4 or 5 files to exclude ( not match ).

Can do this with a FOR cycle or something similar?

osramos

Quote:
Originally Posted by jim mcnamara View Post
You want to find files that DO NOT match the pattern, correct?
ksh allows you to do that:
Code:
#!/bin/ksh
# files that are not named Historicos_Spot_MDI.zip
ls edpst/CargadoresSPOT/!(Historicos_Spot_MDI.zip)
# 
ls edpst/CargadorOmelBroker/!(??????.xls)
#
ls edpst/CargadorOmelReuters/!(CarOmlReuts.xls)
  #4 (permalink)  
Old 09-22-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
What you are asking is to create a resultset that all files minus pattern1 minus pattern2

The only problem for this is that we will have to use grep -v. The file matching patterns become regular expressions
Code:
??????.xls
# becomes regex:
[0-9]{6}\.xls
This will happen for every file you want to exclude. Otherwise, you cannot just
Code:
ls !(pattern)
for five different files because each instance of !(pattern2) will show other patterns like pattern2 pattern3... etc.
Code:
# generalized solution
ls directory | grep -v -e 'regex1' -e 'regex2' -e 'regex3'
Therefore you have to construct 50 different regexes (one for each file you have to specify) and apply some of them to the correct directory output from ls. I cannot do that for you.
  #5 (permalink)  
Old 09-24-2008
osramos osramos is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Oh, i see.

Another problem i have, assuming i'm using " ls !(pattern) ", is the shell i'm using.

The server is a Windows Server but have installed CYGWIN and Bash doesn't recognize the " ! ".

Is there other solution?

Regards,

osramos

Quote:
Originally Posted by jim mcnamara View Post
What you are asking is to create a resultset that all files minus pattern1 minus pattern2

The only problem for this is that we will have to use grep -v. The file matching patterns become regular expressions
Code:
??????.xls
# becomes regex:
[0-9]{6}\.xls
This will happen for every file you want to exclude. Otherwise, you cannot just
Code:
ls !(pattern)
for five different files because each instance of !(pattern2) will show other patterns like pattern2 pattern3... etc.
Code:
# generalized solution
ls directory | grep -v -e 'regex1' -e 'regex2' -e 'regex3'
Therefore you have to construct 50 different regexes (one for each file you have to specify) and apply some of them to the correct directory output from ls. I cannot do that for you.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0