Solved

find matched files

Posted on 2011-03-21
4
296 Views
Last Modified: 2012-05-11
Hi, suppose my current path is /scratch/zh/imp/out. There are 22 sub-directories called "1","2",..."22".
In each sub-folder, there are many .gz files and .summary files. In the normal situation, there is a corresponding .gz file for each .summary file.
But sometimes it is not correct due to lacking of enough cpu time to cause jobs failure.

I want a shell scipt to check the case. If the situation happened, find which folder failed.

Thanks for help.
0
Comment
Question by:zhshqzyc
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
Comment Utility

for i in `find . -type d`
do
	ls -l $i | grep ".gz$" > /dev/null
	[ "$?" eq "0" ] && echo "$i has .gz file" || echo "$i does not have .gz file"
	ls -l $i | grep ".summary$" > /dev/null
	[ "$?" eq "0" ] && echo "$i has .summary file" || echo "$i does not have .summary file"
done

Open in new window

0
 
LVL 23

Assisted Solution

by:Kamaraj Subramanian
Kamaraj Subramanian earned 70 total points
Comment Utility
you can use `find . -maxdepth 1 -type d` for only for one level
0
 
LVL 8

Assisted Solution

by:pilson66
pilson66 earned 60 total points
Comment Utility
script:
 
#!/bin/bash

firstdir="/path/to/dirs"

for t in $(seq 1 22); do
    cd ${firstdir}/${t}
        for w in $(ls *.summary | sed 's/\.summary//g'); do
            if [ ! -f ${w}.gz ]; then
                echo "Error: ${t}: ${w}.gz is absent."
            fi
        done
done

Open in new window


result:
 
./1.sh 
Error: 2: qwe.gz is absent.

Open in new window

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 120 total points
Comment Utility
find /scratch/zh/imp/out -name "*gz" -o -name "*.summary" |sort | sed  s'/\.summary$//;s/\.gz$//' | uniq -u
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now