Need script to find errored files inside directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to find errored files inside directories
# 1  
Old 09-22-2008
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  
Old 09-22-2008
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  
Old 09-22-2008
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
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  
Old 09-22-2008
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  
Old 09-24-2008
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
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find all .sh files in file system and need to replace the string inside .sh files

Hi All, I need to write a script to find all "*.sh" files in /home file system and if any string find "*.sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this. find / -name... (3 Replies)
Discussion started by: bhas85
3 Replies

2. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies

3. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

4. Shell Programming and Scripting

List directories and count files inside

I'm trying to make a script that will list all directories under a selection as well as the number of files in each. I cannot get it to work under a symbolic link. The file structure is: XXX_20131127_001 dir01 (sym link) 2404x912 file.0000.xxx to ... (10 Replies)
Discussion started by: scribling
10 Replies

5. Shell Programming and Scripting

Script to go Into Directories and Find/Delete files

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have... (5 Replies)
Discussion started by: gkelly1117
5 Replies

6. Shell Programming and Scripting

Need help in listing directories inside korn shell script

Hi All, I need to loop through each item in current path, if it is a direcotry do soemthing, if its a file jsut skip it and move to next item in loop. Tried if test ! -d $i then echo "The current item $i is not a directory" continue fi This doesnt seems to be working .... (8 Replies)
Discussion started by: justchill
8 Replies

7. Shell Programming and Scripting

Script to find folders with spaces and end of files and directories

Hi I need a script that can search through a set of directories and can locate any file or directory that has a space at the end Filename(space) Foldername(space) I then need to remove that space within the script Hope someone can help thanks in advance Treds (8 Replies)
Discussion started by: treds
8 Replies

8. Shell Programming and Scripting

deleting files inside shell script - ( using find)

Hi, I am using the command find /apps/qualdb/gpcn/scripts/cab_outbound/archive -name 'z*' -mtime +28 -exec rm {} \; in unix command prompt for deleting the files in my unix system under the specfied folder. It was succesfull. But when i running this command inside a shell script name... (2 Replies)
Discussion started by: Jayaram.Nambura
2 Replies

9. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

10. Solaris

how to find an errored disk

hai all, hope you people will guide me. please suggest me how find an errored disk in a ssa-100 array. what is the error message we get , when a disk fails and where is it logged. iam using solaris 8 version. please help me (2 Replies)
Discussion started by: raj.soladm
2 Replies
Login or Register to Ask a Question