Finding directories with expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding directories with expression
# 8  
Old 02-11-2013
Code:
find * -type d -name mypattern | sed '
  s/_[0-9]*\/mypattern$//
 ' | sort -u | while read p
 do
  sum=0
  ls ${p}_[0-9]/mypattern | xargs -r du -sk | while read k n
   do
    (( sum += k ))
   done
  echo $p $sum
 done

Find the mypattern dirs, remove any parent suffix and the child name, sort unique, and for each, start the sum at zero, find the size of all files in the family of directories and add to sum, and print out a summary line on this pattern.

Last edited by DGPickett; 02-28-2013 at 04:43 PM.. Reason: init sum, no $ for just compute, regex too greedy
This User Gave Thanks to DGPickett For This Post:
# 9  
Old 02-11-2013
is there any way to show all directory without the name of directory in pattern.

Code:
find server/ \( ! -name mypattern  -prune \)
result:
server/1234567_1/mypattern
server/1234567_2/mypattern
server/1234567_3/mypattern
server/1234567_4/
server/1234567_5/mypattern

this would be the result only
server/1234567_4/

thanks
# 10  
Old 02-12-2013
Code:
awk '!/mypattern/'

Code:
awk '$0!~p' p="mypattern"

This User Gave Thanks to Jotne For This Post:
# 11  
Old 02-26-2013
Quote:
Originally Posted by Jotne
Code:
awk -F"[ _]" '$0~p {a[$3]+=$1} END {for (i in a) print a[i]"k "i"/"p}' p="mypattern" server1 > result.txt
cat result.txt
200k 123456/mypattern
600k 123457/mypattern

your script works now, but I noticed that if you have directory like this:
Code:
10k ab_12444_1/mypattern
10k ab_12444_2/mypattern
20k ab_12444/mypattern

Code:
cat result.txt
20k 12444/mypattern

instead of 
40k 12444/mypattern

is there any fix for this?

thanks
# 12  
Old 02-27-2013
I removed a couple bugs in my script above.
This User Gave Thanks to DGPickett For This Post:
# 13  
Old 02-28-2013
where's the script sir?
this script sir?
Code:
find * -type d -name mypattern | sed '   s/.*_[0-9]*\/mypattern$//  ' | sort -u | while read p  do   sum=0   ls ${p}_[0-9]/mypattern | xargs -r du -sk | while read k n    do     (( sum += k ))    done   echo $p $sum  done

Thanks
# 14  
Old 02-28-2013
Yes, above -- I fixed it some more and added a narrative.
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with Regular expression now working on file directories

Hello Everyone, I have a file sam1 with the below content SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1 echo $Regex \bSYSYSID\b|\bMANDT\b|\b/SIE/AD_Z0M_INDX\b|\b/SIE/AD_Z0M_KEY1\b cat sam1 | grep -Eo $Regex I expect the result as SYSYSID MANDT /SIE/AD_Z0M_INDX /SIE/AD_Z0M_KEY1... (4 Replies)
Discussion started by: sam99
4 Replies

2. UNIX for Advanced & Expert Users

Regular expression for finding OCR mistakes.

I have a large file of plain text, created using some OCR software. Some words have inevitably been got wrong. I've been trying to create grep or sed, etc., regular expressions to find them - but haven't quite managed to get it right. Here's what I'm trying to achieve: Output all lines which... (2 Replies)
Discussion started by: gencon
2 Replies

3. UNIX for Dummies Questions & Answers

Finding multiply directories

I have multiply directories scattered throughout my system that end in 2011. Example: one_2011 two_2011 three_2011 etc.... I'm trying to find all of these directories but coming up short. I tried find / -type d -name *2011 > example Any suggestions? I already searched in the... (13 Replies)
Discussion started by: shorty
13 Replies

4. UNIX for Dummies Questions & Answers

Finding size of all directories

Alright so I've tried a couple different things that at first glance, looked like they worked. find . -maxdepth 5 -type d -daystart -mtime 1 | xargs du -h Which seems to ignore the previous commands such as depth and modified time. find .. -maxdepth 2 -type d -daystart -ctime 1 | xargs... (8 Replies)
Discussion started by: Aussiemick
8 Replies

5. UNIX for Dummies Questions & Answers

using regular expression for directories in find command

Hi, I want to find the files available in a directory /var/user/*/*/data/. I tried using the command "find /var/user/ -path '*/*/data/ -name '*' -type f" it says find: 0652-017 -path is not a valid option and then i tried using "find /var/user/ -name '*/*/data/*' -type f" but its not... (3 Replies)
Discussion started by: vinothbabu12
3 Replies

6. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

7. Shell Programming and Scripting

finding correct directories

I have directories like V00R01,V00R02,V01R01,V01R02 in a directory where V is version and R is a release. basically I need to set base directory and current directory. Under a version there can be any number of releases and there can be number of versions also. V00R01...V00R50..so on also,... (2 Replies)
Discussion started by: vjasai
2 Replies

8. UNIX for Dummies Questions & Answers

Create directories with regular expression

Hi guys, can any one tell me how to create directories using regular expression? Let's say that I need to create directories test01, test02, test03.... test10. Can it be done using any regular expression? thanks. (13 Replies)
Discussion started by: mahendrt
13 Replies

9. Shell Programming and Scripting

Expression for Finding Multiple Directories..??

I am writing a shell script to search for previous versions of an application...the application is called TAU and basically i want to search the users home directory and /Applications for any instances of a "TAU" folder.. If found i want to give the user the option to remove the old folders and if... (3 Replies)
Discussion started by: meskue
3 Replies

10. UNIX for Dummies Questions & Answers

finding directories in UNIX

I am accessing a UNIX server via FTP. I want to retieve a file in a directory. What is the UNIX command that I need to view and retrieve files from a directory? (1 Reply)
Discussion started by: yodaddy
1 Replies
Login or Register to Ask a Question