Computing.Net > Forums > Linux > Reading files in multiple directori

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Reading files in multiple directori

Reply to Message Icon

Name: yacob
Date: March 20, 2008 at 10:22:17 Pacific
OS: linux
CPU/Ram: 2GB
Comment:

Dear All,

I want a script that go through all sub directories in a given directory and then go through all the files in a given subdirectory and then I will work out what I want on the files. I have 365 directories in each of the subdirectory comprise 8 files. I want to read each file and run a program on each of the files.

I have been so far able to run a script in one directory as:

for i in *.grd ;

do

bala bala

done

I beleive I need two "For" loops one that reads directory and the other one files. Thank your in advance.

Yacob



Sponsored Link
Ads by Google

Response Number 1
Name: yacob
Date: March 20, 2008 at 10:42:18 Pacific
Reply:


I think I answered the question my self. If any want interested in the script, this looks simple and it is:

#!/bin/bash
for b in *;
do ( cd $b;
for a in *;
do
echo $a ;

done );
done

This script goes through each directory and looks for each file. Now my question remain, is it possible that to determine the number of directory that I want to read. For instanc e I want to read only directories that are created in one month of the year: from directiry 1-30. Or from 31-61.

Yacob


0

Response Number 2
Name: yacob
Date: March 20, 2008 at 11:08:12 Pacific
Reply:


I found the answer to my last question. To read just part of the directory I used the following so that I control how many directory I read before I start the do loop on the file.


str=`ls /home/2002 | head -30`

for file in /home/2002/$str ;

do ( cd $file;
for a in *;
do
echo $a ;

done );
done


The script goes only over the first 30 directories and then go over each files. I have still a problem. How can I read only selected directories, like in the first month not all 30 directories but only 28 of them but not necessarliy the first 28 or the last 28 of them. How this can be done ?

Thank you.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Reading files in multiple directori

Script for read files in a director www.computing.net/answers/linux/script-for-read-files-in-a-director/28504.html

renaming many files in similar way www.computing.net/answers/linux/renaming-many-files-in-similar-way/17025.html

prepend text to all files in dir www.computing.net/answers/linux/prepend-text-to-all-files-in-dir/28993.html