Solved

find matched files

Posted on 2011-03-21
4
303 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

752 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