Solved

find matched files

Posted on 2011-03-21
4
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35181475

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
ID: 35181519
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
ID: 35181651
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
ID: 35181821
find /scratch/zh/imp/out -name "*gz" -o -name "*.summary" |sort | sed  s'/\.summary$//;s/\.gz$//' | uniq -u
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

635 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