Print all the directory with no directory name mydir


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print all the directory with no directory name mydir
# 1  
Old 02-12-2013
Print all the directory with no directory name mydir

directory structure:
Code:
100k server1/ab_1234567_1/mydir
500k server1/ab_1234567_2
100k server1/ab_1234567_3/mydir
100k server1/ab_1731458_9/mydir
600k server1/ab_1234569_1
100k server1/ab_1234569_4/mydir
100k server1/ab_1234510_40/mydir
800k server1/ab_1234511_1

is there any way to generate the result ?
is there any possible solution for this?
googling like this very difficult.


result:
Code:
500k 1234567
200k 1234567/mydir
100k 1234568/mydir
600k 1234569
100k 1234569/mydir
100k 1234510/mydir
800k 1234511

thanks

Last edited by lxdorney; 02-12-2013 at 12:27 PM..
# 2  
Old 02-12-2013
Maybe if you explained a bit more what we are looking at, and what you want (which doesnt seem to be what you mentionned in the title:
Quote:
Print all the directory with no directory name mydir
We could try to help you but here I must say I am confused...
e.g.
Code:
100k server1/ab_1234567_1/mydir

if this is a directory structure what is the meaning of the space after the initial 100k?
Or should you first tell us what your OS is and the shell you are using...
# 3  
Old 02-12-2013
This is nearly the same as you have asked before.
Learn how to use Field Separator and print formatting in awk, and you can tweak this yourself.
# 4  
Old 02-12-2013
Just go step by step. First get the list of prefixes, sorted unique, then for each make a total for the prefix_*/, then detect any prefix_*/mydir/ and if present make a total for that.
Code:
ls server/ab_*_*/|sed '
  s/^server.ab_\([0-9]*\)_[0-9]*.$/\1/
 ' | sort -u | while read pfix
 do
  sum=0
  du -sk server/ab_${pfix}_* | while read k n
   do
    (( sum += k ))
   done
  echo ${sum}k $pfix
  sum=0
  du -sk server/ab_${pfix}_*/mydir | while read k n
   do
    (( sum += k ))
   done
  if [ $sum = 0 ]
   then
    continue
   fi
  echo ${sum}k $pfix/mydir
 done

# 5  
Old 02-13-2013
thank for the response and yes that what exactly I want, but executing the script I got error message:

and here is my process:
Code:
pwd
/root

Code:
ls server
ab_1234510_40  ab_1234511_1  ab_1234567_1  ab_1234567_2  ab_1234567_3  ab_1234569_1  ab_1234569_4  ab_1731458_9

Code:
nano test3.sh
then copy and paste your script

Code:
./test3.sh
du: cannot access `server/ab__*': No such file or directory
0k
du: cannot access `server/ab__*/mydir': No such file or directory
du: cannot access `server/ab_file.txt_*': No such file or directory
0k file.txt
du: cannot access `server/ab_file.txt_*/mydir': No such file or directory
du: cannot access `server/ab_mydir_*': No such file or directory
0k mydir
du: cannot access `server/ab_mydir_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234510_40/:_*': No such file or directory
0k server/ab_1234510_40/:
du: cannot access `server/ab_server/ab_1234510_40/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234511_1/:_*': No such file or directory
0k server/ab_1234511_1/:
du: cannot access `server/ab_server/ab_1234511_1/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234567_1/:_*': No such file or directory
0k server/ab_1234567_1/:
du: cannot access `server/ab_server/ab_1234567_1/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234567_2/:_*': No such file or directory
0k server/ab_1234567_2/:
du: cannot access `server/ab_server/ab_1234567_2/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234567_3/:_*': No such file or directory
0k server/ab_1234567_3/:
du: cannot access `server/ab_server/ab_1234567_3/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234569_1/:_*': No such file or directory
0k server/ab_1234569_1/:
du: cannot access `server/ab_server/ab_1234569_1/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1234569_4/:_*': No such file or directory
0k server/ab_1234569_4/:
du: cannot access `server/ab_server/ab_1234569_4/:_*/mydir': No such file or directory
du: cannot access `server/ab_server/ab_1731458_9/:_*': No such file or directory
0k server/ab_1731458_9/:
du: cannot access `server/ab_server/ab_1731458_9/:_*/mydir': No such file or directory


Last edited by lxdorney; 02-13-2013 at 12:12 AM..
# 6  
Old 02-14-2013
any update for the above error

thanks
# 7  
Old 02-14-2013
Well, sometimes it is cheaper to "2>/dev/null" than to test for potential directories or files.
  • You can test inside 'for x in zzz*;do ... done' to see if x is literally "zzz*" and continue. Note that the shell does all the work expanding glob expressions like zzz* without the cost of a fork()/exec() of 'ls' or 'find'.
  • The form 'ls zzz* 2>/dev/null | while read e' does nothing if zzz* does not expand, ls errors it out on stderr and it is never read from stdout pipe stdin into e, unlike the 'for' case.
  • The 'find' command does not complain or provide unexpanded glob expressions like 'zzz*', but it goes down the tree, whereas 'ls' just does the dirs or files (and unexpanded glob expressions like 'zzz*') it is given.

Last edited by DGPickett; 02-14-2013 at 02:38 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loop through directory and print on line

In the bash below I am trying to loop through all the R1.gz in a directory (always 1), store them in ARRAY, and cut them before the second _. That is being done but I can't seem to print then one a single line seperated by a space. Is the below the best way or is there a better solution? Thank you... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. UNIX for Advanced & Expert Users

A way to print only part of directory path

Hi, So I struggled to find a solution to the following problem: I want to make sed print only part of multiple different paths. So lets say we have /path/path1/path2/logs/bla/blabla /path/path1/path2/path3/logs/yadda/yadda/yadda Can someone suggest a way to make sed or other... (5 Replies)
Discussion started by: dampio
5 Replies

3. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

4. Shell Programming and Scripting

Print the current directory using perl

Hi I have this code to print the current directory using Perl use Cwd qw(abs_path); my $path = abs_path($0); print "$path\n"; But it is displaying my perl source code file along with the directory. like this C:\Perl\duration.pl But I want it only to display this... (1 Reply)
Discussion started by: srijith
1 Replies

5. Shell Programming and Scripting

[awk] print all filenames in directory

Hello, I was given a (I suppose) a simple task which I don't know how to do. Before coming here I have read a dozen of awk tutorials (full read, not just line-skipping) but I still don't know how to do this. Task: Write an script file 'check.awk' with a parameter current directory that... (5 Replies)
Discussion started by: c0dehunter
5 Replies

6. Shell Programming and Scripting

Print directory name along with their path

Can any one tell me that how can i print all directory with their path in a given parent directory. i.e. parent directory /home/usr/ Now this shoe directory may contain sevral directory /home/usr dir1/ dir1.1/ dir1.2/ dir2 dir2.1/ dir2.2/ ... (5 Replies)
Discussion started by: jadoo_c2
5 Replies

7. Solaris

delete buffer from print directory

Hi all, Operting system : Solaris 9 Oracle application: 11.5.10 i would like to ask query related to buffer area of pinter on solaris server. we are trying to print cheques using oracle application on network printer. some times it is printing the cheques with out any problem but... (1 Reply)
Discussion started by: maooah
1 Replies

8. Shell Programming and Scripting

How to print a directory list to a file?

I have directory of files listed with stats. I need to print only files with the same stats to a file. I tried this, and it printed a blank document. *1556 > tmp/list it did not work any suggestions? (3 Replies)
Discussion started by: rocinante
3 Replies

9. Shell Programming and Scripting

print all files of a directory

At the moment I do not know anything UNIX script :rolleyes: but i need to make script that prints the content of the archives (of text) that are deposited in a directory and Later erases these archives, leaving the directory emptiness It would be like repository for print please... (9 Replies)
Discussion started by: monica
9 Replies
Login or Register to Ask a Question