using find in for loop


 
Thread Tools Search this Thread
Operating Systems AIX using find in for loop
# 8  
Old 09-02-2008
If the subdirectory structure is only one deep, you can still use that.

Code:
for i in *.sh */*.sh; do
  : stuff with "$i"
done

# 9  
Old 09-02-2008
hi lakris,

i dont think it will suite to my situation coz,
1. i cannot use fixed values like "/home/training" & "*.sh". i hv to go for variables only.
2. i want files from the sub-dirs too and not alone the current dir(say, /home/training).
# 10  
Old 09-02-2008
It's certainly not impossible to use variables here.

Code:
find "$src" -name "$typ" |
while read i; do
  : ...
done

... nor here:

Code:
for i in $src/$typ $src/*/$typ $src/*/*/$typ; do

(Of course, that doesn't work for arbitrarily deeply nested subdirectories; as indicated before, you have to enumerate each subdirectory level. But if you know e.g. that it always only goes one level deep, this is certainly an option.)
# 11  
Old 09-02-2008
hi era,

i wont be able to predict the depth of sub-dirs. also, i need to go for variable inputs and cannot write *.sh as such. that i had given as an example. it could be different at different times. basically, those two values("/home/training" & "*.sh") i will be reading from an INI file.

and since its given as a variable, all these issues are coming. i am NOT adamant that i want to use "find" itself. any other solution will do for me. only thing is, i want to get all the 'typ' files from 'src' dirs. thats what i can put it in a nutshell. Smilie

anybody pls help me as i'm very much required it urgently... Smilie

tia
Smilie
Muthursyamburi
# 12  
Old 09-02-2008
I noticed you used single quotes when you tried the while loop. That's wrong; single quotes prevent variable expansion. Use double quotes (or simply copy/paste what I wrote above).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

While loop, input from find command

Hello nix Experts, I am a *nix rookie and have run into this issue, can some one help me here and let me know what I am doing wrong. /home/user1> while read n > do > echo $n > done < <(find . -type f -ctime -1 | grep abc) I am getting the below error: -sh: syntax error near... (5 Replies)
Discussion started by: babyPen1985
5 Replies

2. UNIX for Dummies Questions & Answers

find command in for loop

i have executed the following command in terminal find /Users/vasu -name "*.txt" -print and i am getting the result /Users/vasu/file1.txt /Users/vasu/file2.txt /Users/vasu/file3.txtbut while i was trying to execute the same in the script it is not working,I tried with below logic in... (2 Replies)
Discussion started by: vmachava
2 Replies

3. Shell Programming and Scripting

Loop with Find—damn spaces!

Hi Guys, I'm trying to find all files with a particular extension and then loop some actions. The problem is that if the files have spaces in their names I get end up being each word as a separate result rather than the entire file. ext=".txt" out=".rtf" for i in $( find "$1" -name "*$ext" );... (9 Replies)
Discussion started by: imonkey
9 Replies

4. Shell Programming and Scripting

find in for loop

whats wrong with this script for i in Users.csv abd.csv > do > find . -name $i > done (2 Replies)
Discussion started by: theshashi
2 Replies

5. Shell Programming and Scripting

find in for loop

What's wrong with this script for i in Users.csv anc.csv > do > find . -name $i > doneDouble post. Continue here. (0 Replies)
Discussion started by: theshashi
0 Replies

6. Shell Programming and Scripting

Find result using for loop

I want to print each file i found using the find command. And not able to list the files at all here is the code SEARCH_DIR="/filesinfolder"; PATH_COUNT=0 for result in "'/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a -name '*.csv' \) -o -name '*_xyz_*' \) -mtime 1'" do... (1 Reply)
Discussion started by: nuthalapati
1 Replies

7. Shell Programming and Scripting

find a string in a loop

Hi, Can anyone help with the problem below? I need to read all text files (file1, file2, file3) in a loop and find file1.txt: file2.txt: File3.txt: (7 Replies)
Discussion started by: Lenora2009
7 Replies

8. Shell Programming and Scripting

Help in loop find question at STEP 3

STEP 1 # Set variable FILE=/tmp/mainfile SEARCHFILE =/tmp/searchfile cat /tmp/mainfile Interface Ethernet0/0 "outside", is up, line protocol is up Hardware is i82546GB rev03, BW 100 Mbps Full-Duplex(Full-duplex), 100 Mbps(100 Mbps) MAC address 001e.f75e.8cb4, MTU 1500 IP address... (1 Reply)
Discussion started by: irongeekio
1 Replies

9. Shell Programming and Scripting

Loop and find not working ASAP

I grep some thing from file then in a loop give to find one by one but not working. #!/bin/bash grep -H DocumentRoot /etc/httpd/conf.d/*.conf | awk -F' ' '{ print $3 }'| sort -u | uniq > path.txt for j in `cat path.txt` do # echo "line is $i" find "$j" -type d... (3 Replies)
Discussion started by: aliahsan81
3 Replies

10. Shell Programming and Scripting

For Loop with find

I'm trying to write a script to archive some log files, and I'm getting a little stuck. My 'find' command by itself works great, returning all of the log files I need, but when I try to combine it with my loop, I'm getting an error. Here's what I have so far: for FILENAME in $(find . -type f... (4 Replies)
Discussion started by: kadishmj
4 Replies
Login or Register to Ask a Question