for


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting for
# 1  
Old 04-16-2008
Question for

Hi,

How can I read all the files recursively from $path modifying this code?

$path="/"

for file in *.txt
do
<read_all_the_txt_files>
done
# 2  
Old 04-16-2008
Code:
find / -type f -name '*.txt' -exec cat {} \;

1. be sure you a have a LOT of time to do this.
2. you may want to add a
Code:
find / -type f -name '*.txt' -exec cat {} \; | more

so the screen doesn't scroll by too fast
# 3  
Old 04-16-2008
Hammer & Screwdriver The following wil print to screen every text file found

Note: the -R tells ls to work recursively

Code:
for filex in $(ls -R -l | grep .txt)
  do 
  cat $filex
done

# 4  
Old 04-16-2008
Quote:
Originally Posted by jim mcnamara
Code:
find / -type f -name '*.txt' -exec cat {} \;

1. be sure you a have a LOT of time to do this.
2. you may want to add a
Code:
find / -type f -name '*.txt' -exec cat {} \; | more

so the screen doesn't scroll by too fast
.

Ok, but how could I use it in a for statement?

I tryed:
Code:
for file in (find /Users/mirko/Unix -type f -name '*.txt')
do
...

But it doesn't work.
# 5  
Old 04-17-2008
Can anyone answer me, please?
# 6  
Old 04-17-2008
Hi

for example

for file in `find /Users/mirko/Unix -type f -name '*.txt'`
do
echo ${file}
done
# 7  
Old 04-17-2008
Now that I know how to insert that part of code in a for I understood that it doesn't work correctly.

Example:
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/Happy.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt

Ok.

But, another example: (after I changed the files)
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/Happy.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio
Ga
Ga.txt
/Users/mirko/Unix/Save
Me.txt
/Users/mirko/Unix/Seven
Seas
Of
Rhye.txt


So the files with a space " " in their name are splitted in two lines.

Any advice?
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question