Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Please help me on how to loop subdirectories Post 302471057 by ksgreen on Thursday 11th of November 2010 09:51:35 PM
Old 11-11-2010
Thank you very much!

Here is what I need to do. Thanks a lot!

The folder structure is

under f1 and f2,

a list of subfolders, some contain folder name containing "abcde"
if there is "abcde", then there is file in "*abcde*" named "file.txt", then I will grep "xxyyzz"
if there is no folder name containing "abcde", then I need to go back and go to another subfolders and continue

then all the patterns will be stored in a file new$f

-------------------
for f in f1 f2
do
cd $f
#then I need to loop one layers sub directories and if there is folder named "abcde", I need to grep pattern from "file.txt". If no folder "abcde", then back one layer up and repeat finding "abcde" --- how to do this? Thanks a lot!

#find the "file.txt" and grep pattern
find .-name "file.txt" -exec grep "xxyyzz" {} \; > new$f
cd ..
done

Last edited by ksgreen; 11-11-2010 at 11:42 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to search all subdirectories?

Dear All, I want to write the Unix command that searches through all subdirectories, finds the files named ''core'' and deletes them. I will very much appreciate your help. David (4 Replies)
Discussion started by: david_wang
4 Replies

2. Solaris

/home Subdirectories

Hello: Could someone please explain to me how to create a subdirectory in the /home directory. I have tried creating a new user but the default path for a new user is /export/home. I am running Unix 5.8 on a Sun Blade 100. Thanks. (8 Replies)
Discussion started by: mawalton
8 Replies

3. UNIX for Dummies Questions & Answers

how to see all the subdirectories easily?

Suppose I have two directories a and b. Each directory has a few subdirectories, a1 a2 a3 and b1, b2, b3 respectively. Using ls, I can see a and b. Then I need cd a, ls, cd ../b, ls to see all the subdirectories. How to see all the directories and subdirectories easily, say using just one... (2 Replies)
Discussion started by: fld2007
2 Replies

4. Shell Programming and Scripting

Loop through subdirectories to gzip files

I have a directory has many subdirectories. Each subdirectories has several very large files. Some of the large files already compressed (*.Z). I need to uncompress those files if they are *.Z files then gzip them to save more space. But those files are too large so they can only be done uncompress... (2 Replies)
Discussion started by: visio2000
2 Replies

5. Shell Programming and Scripting

Please help me on how to loop subdirectories

Here is my question in bash for f in f1 f2 do cd $f cd ??? # i need to enter the two layers of sub folders then find the folder named "abcde" ? cd .. # how to get out two layers subdirectories? cd .. done (3 Replies)
Discussion started by: ksgreen
3 Replies

6. UNIX for Dummies Questions & Answers

Testing for subdirectories

Hello, Can anyone help me figure out how to test if the item in the directory is a subdirectory? I'm writing a code to copy all the contents of directory1 to directory2, but I want to skip all the subdirectories. Thanks! (4 Replies)
Discussion started by: l flipboi l
4 Replies

7. Shell Programming and Scripting

diff different subdirectories

I have 2 directories a/ and b/, they have different subdirectories, how to diff with missing file, or missing subdirectory and if i have in a/ directory "a/ACD/DEF" DEF is a file, but in b/ directory "b/ACD/DEF is a SUBDIRECTORY, how to diff it, thanks my solution for directories, ... (7 Replies)
Discussion started by: knajta
7 Replies

8. Linux

Stats on subdirectories

Please help me with a shell script to get the stats on many subdirectories (sub1), (sub2) etc under a mother directory (big) /big | |_______sub1 |_______sub2 |_______sub3 --------- I want to know 1. What is the last file accessed in each subdirectory with date and by whom 2.... (2 Replies)
Discussion started by: digipak
2 Replies

9. Shell Programming and Scripting

sed through all subdirectories?

I found this awesome sed script here: https://www.unix.com/shell-programming-scripting/48228-perl-search-string-line-then-search-replace-text.html sed -i '/MatchText/ s/ReplaceMe/REPLACED/' filename Question though to save me manually doing this. How do I do this from a root directory... (6 Replies)
Discussion started by: Astrocloud
6 Replies

10. UNIX for Dummies Questions & Answers

Foreach loop through subdirectories in csh

Hi You might find it very trivial but actually don't know how to loop through all sub-directories and their child directories into a csh. bash was easier I believe but here I am, stuck with csh. So elaborately here's my problem: Let's say I have my parent directory named C-H/ under which I have... (15 Replies)
Discussion started by: saleheen
15 Replies
NEW(1)								     [nmh-1.5]								    NEW(1)

NAME
new - report on folders with new messages fnext - set current folder to next folder with new messages fprev - set current folder to previous folder with new messages unseen - scan new messages in all folders with new messages SYNOPSIS
new [sequences] [-mode mode] [-folders foldersfile] [-version] [-help] fnext is equivalent to new -mode fnext fprev is equivalent to new -mode fprev unseen is equivalent to new -mode unseen DESCRIPTION
New in its default mode produces a one-line-per-folder listing of all folders containing messages in the listed sequences or in the sequences listed in the profile entry "Unseen-Sequence". Each line contains the folder, the number of messages in the desired sequences, and the message lists from the .mh_sequences file. For example: foo 11.* 40-50 bar 380. 760-772 824-828 total 391. The `*' on foo indicates that it is the current folder. The last line shows the total number of messages in the desired sequences. New crawls the folder hierarchy recursively to find all folders, and prints them in lexicographic order. Override this behavior by provid- ing foldersfile containing the pre-sorted list of folders new should check, one per line. In fnext and fprev modes, new instead changes to the next or previous matching folder, respectively. In unseen mode, new executes scan sequences for each matching folder. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder Unseen-Sequence: The name of the unseen message sequence SEE ALSO
scan(1), mh-format(5) HISTORY
Based on Luke Mewburn's new (http://www.mewburn.net/luke/src/new). MH.6.8 11 June 2012 NEW(1)
All times are GMT -4. The time now is 01:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy