Results 1 to 6 of 6
Hi all,
I want to write a shell script which reads the directory and its sub directories and find whether .c files are there if there i have get the ...
- 06-19-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 14
How to read directory in shell script
Hi all,
I want to write a shell script which reads the directory and its sub directories and find whether .c files are there if there i have get the name of the files individually. Can any one help them.How to use awk in the while loop too.
Regards,
Yugandhar.
- 06-19-2007 #2
A good start is to use find. If you want to do something to each of the files, then something like:
Code:#!/bin/bash for file in $(find $1 -type f -iname '*.c'); do (What to do with the files, replacing filename with $file) done
"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
- 06-19-2007 #3Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
or try grep: "ls -R |grep *.c"
the sun is new every day (heraclitus)
- 06-19-2007 #4
This would work if it was JUST the filenames that you wanted, but if you also wanted their location, then the find method would be preferable since it includes that information. iirc, ls -R simply shows each directory's list under the folder name eg:
folder:
file1
file2
file3
folder2:
file4
file5
file6"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
- 06-20-2007 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 14
How to read a directory using shell script
Hi ,
After getting all the .c files i will store it in a file and i have to read the file and get the names of the .c files one by one up to end of the file. How can i read one line at a time from a file.
- 06-20-2007 #6
If you use the find method i posted above, you dont need to post the file names out to a file, just include what you want done to the file in the loop.
"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327


Reply With Quote
