bash : doubt in find
am 06.01.2005 05:21:02 von saravanan.linux
Hi,
i' trying to display files which is output{filtered} from find. Not
able to get expected o/p, if filename contains space.
here is the script which i'm trying.
1. #!/bin/bash
2. for i in `find . -iname '*.txt'`
3. do
4. echo $i
5. done
For example if current directory contains following files
"1.c" "2.c" "test.txt" "test file name.txt"
o/p from above script is:
-------------------------
../test
file
name.txt
../a.txt
===========================================
expected o/p:
../test file name.txt
../a.txt
Please give me sugg to get this result.
Thank you
Saravanan.
Re: bash : doubt in find
am 06.01.2005 05:47:52 von Icarus Sparry
On Wed, 05 Jan 2005 20:21:02 -0800, saravanan.linux@gmail.com wrote:
> Hi,
> i' trying to display files which is output{filtered} from find. Not
> able to get expected o/p, if filename contains space.
> here is the script which i'm trying.
>
> 1. #!/bin/bash
> 2. for i in `find . -iname '*.txt'`
> 3. do
> 4. echo $i
> 5. done
>
> For example if current directory contains following files
>
> "1.c" "2.c" "test.txt" "test file name.txt"
>
> o/p from above script is:
> -------------------------
> ./test
> file
> name.txt
> ./a.txt
> ===========================================
> expected o/p:
> ./test file name.txt
> ./a.txt
> Please give me sugg to get this result.
The normal thing to do is
find . -iname '*.txt' | while read -r fn
do
echo "$fn"
done
This works as long as you don't have 'newline' characters in your
filenames. The advantage of writing it this way is that you are not
buffering up large amounts of filenames, and you can process the files in
parallel with generating the list of files.
Re: bash : doubt in find
am 06.01.2005 05:54:30 von Ed Morton
saravanan.linux@gmail.com wrote:
> Hi,
> i' trying to display files which is output{filtered} from find. Not
> able to get expected o/p, if filename contains space.
> here is the script which i'm trying.
>
> 1. #!/bin/bash
> 2. for i in `find . -iname '*.txt'`
> 3. do
> 4. echo $i
> 5. done
>
> For example if current directory contains following files
>
> "1.c" "2.c" "test.txt" "test file name.txt"
See question 16 in the FAQ (http://home.comcast.net/~j.p.h/cus-faq.html#P).
Ed.
> o/p from above script is:
> -------------------------
> ./test
> file
> name.txt
> ./a.txt
> ===========================================
> expected o/p:
> ./test file name.txt
> ./a.txt
> Please give me sugg to get this result.
>
> Thank you
>
> Saravanan.
>
Re: bash : doubt in find
am 06.01.2005 06:34:21 von Rakesh Sharma
saravanan.linux@gmail.com wrote:
> Hi,
> i' trying to display files which is output{filtered} from find. Not
> able to get expected o/p, if filename contains space.
> here is the script which i'm trying.
>
> 1. #!/bin/bash
> 2. for i in `find . -iname '*.txt'`
> 3. do
> 4. echo $i
> 5. done
>
> For example if current directory contains following files
>
> "1.c" "2.c" "test.txt" "test file name.txt"
>
> o/p from above script is:
> -------------------------
> ./test
> file
> name.txt
> ./a.txt
> ===========================================
> expected o/p:
> ./test file name.txt
> ./a.txt
>
why not use the -print option of 'find'??
find . -iname '*.txt' -print