indication of find activity - bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting indication of find activity - bash script
# 1  
Old 07-29-2010
indication of find activity - bash script

Hi All,

I wanted to show on stdout that a file was found right after it happens due to indicate the activity of long search. Further more I want to store the result of the find in a file.

I have tried this:
Code:
echo -n "Searching"
find . -name Makefile -type f -print -exec echo -n "." \; > testPaths.log

Unfortunately dots are written to the file.
How could I separate output of -exec and result of find? or How could I indicate the find activity?
# 2  
Old 07-29-2010
What about:
Code:
echo -n "Searching"
find . -name Makefile -type f -print -exec echo -n "." | tee -a testPaths.log

?
# 3  
Old 07-29-2010
Or:

Code:
find . -name Makefile -type f 2> /dev/null | while read FILE; do printf "."; echo $FILE > testPaths.log; done

# 4  
Old 07-29-2010
Code:
find . -name Makefile -type f -print -exec echo -n "." | tee -a testPaths.log

prints dot and path to both file and stdout due to piping (dot is printed right after a file is found)

while

Code:
find . -name Makefile -type f 2> /dev/null | while read FILE; do printf "."; echo $FILE > testPaths.log; done

prints the right characters to right places, but the printing of dot is execute just after the find finishes its work on the whole directory set.

Any other idea?

(at this point the piping mechanism is not clear for me: why tee is executed after each file found and why not executed while (just at the end)? Maybe this is the behaviour of while (like xargs echo)?)
# 5  
Old 07-29-2010
I don't know if it works but I think it should work ^^'
Code:
find . -name Makefile -type f -print -exec tee -a testPaths.log | echo -n "."

What it is supposed to do:
first writes the found file to testPaths.log and then echo a dot, not the other way around
Sorry for explaining so bad ^^'
btw @scottn: if you take a look at find's man page:
Quote:
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered.
maybe thats why it doesn't print the dot directly to stdout? Sorry I could also be terribly wrong about it ^^'

Last edited by al0x; 07-29-2010 at 09:56 AM.. Reason: typos non-stop >.>
# 6  
Old 07-29-2010
Quote:
Originally Posted by vercsab
but the printing of dot is execute just after the find finishes its work on the whole directory set.
Why would it do that?

Perhaps it just runs too quickly for you to see.

Try putting a sleep (or usleep) in to test.

---------- Post updated at 03:02 PM ---------- Previous update was at 02:52 PM ----------

Quote:
Originally Posted by al0x
btw @scottn: if you take a look at find's man page:

maybe thats why it doesn't print the dot directly to stdout? Sorry I could also be terribly wrong about it ^^'
Hi.

I didn't use -exec.

The dots print perfectly fine, just, as I said too quickly. But when it finds a file, it prints a dot.
# 7  
Old 07-29-2010
Quote:
Hi.

I didn't use -exec.

The dots print perfectly fine, just, as I said too quickly. But when it finds a file, it prints a dot.
upps didn't see you didn't use it Smilie sry^^'
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find Memory and activity from command output

Hello - I have a requirement to get the Memory(Xmx) and the activity name using it. Sample input info : 1502 02:57 /bin/sh /opt/rather/bar/deploy/bar_run.sh 1545 02:57 java -Drather.repository=/opt/rather/bar/deploy/JobSyng_Barol_Count/JobSyng_Barol_Count/../lib -Xms1024M... (3 Replies)
Discussion started by: Varja
3 Replies

2. Programming

Bash script - find command with delete and exec

hi all, i have devised a script that starts in /restored/ and in there, there are a lot of sub folders called peoples names and in the sub folders are files/folders and it deletes the data in the sub folders BUT not the sub folder itself and it should then touch a file in all the sub folders... (3 Replies)
Discussion started by: robertkwild
3 Replies

3. Shell Programming and Scripting

Bash script to find comments in file

As I stated in a previous thread - I'm a newbie to Unix/Linux and programming. I'm trying to learn the basics on my own using a couple books and the exercises provided inside. I've reached an exercise that has me stumped. I need to write a bash script that will will read in a file and print the... (11 Replies)
Discussion started by: ksmarine1980
11 Replies

4. Shell Programming and Scripting

BASH script problem using find, ideas?

Hi, I'm trying to write a script to search through my computer and find all .jpg files and put them all in a directory. So far I have this: for i in `find /home -name '*.jpg' ` ; do mv $i home/allen/Pictures/PicturesFound ; done When I run it, I get this error (this is only part of it, it... (2 Replies)
Discussion started by: FortressPTH
2 Replies

5. Shell Programming and Scripting

Find associated strings in a bash shell script

Hi together, unfortunately I am not a shell script guru - the following might touch the depths of awk, substr, split, regexps, where I am still fighting with - but as always the boss needs a fast solution :-( So: I have the following USER/PASSWORD-installation-config-file, from where I want to... (10 Replies)
Discussion started by: Sofie
10 Replies

6. Shell Programming and Scripting

Bash Script to Find the status of URL

#!/bin/bash timevar=`date +%d-%m-%Y_%H.%M.%S` #-- > Storing Date and Time in a Variable get_contents=`cat urls.txt` #-- > Getting content of website from file. Note the file should not contain any http:// as its already been taken care of echo "Datae-time URL Status code Report" >... (2 Replies)
Discussion started by: anishkumarv
2 Replies

7. Programming

Bash Script to Find the status of URL

#!/bin/bash timevar=`date +%F_”%H_%M”` #-- > Storing Date and Time in a Variable get_contents=`cat urls.txt` #-- > Getting content of website from file. Note the file should not contain any http:// as its already been taken care of ######### Next Section Does all the processing ######### for i... (0 Replies)
Discussion started by: anishkumarv
0 Replies

8. Shell Programming and Scripting

Find out the day in Bash Shell script

Hello All, I need a bash shell script to find out a day from the date.For example we give the date(20100227/YYYYMMDD) then we get the day 'Saturday'. Thanks in advance, Satheesh (5 Replies)
Discussion started by: satheesh4093
5 Replies

9. Shell Programming and Scripting

Bash script (using find and grep)

I'm trying to make a simple search script but cannot get it right. The script should search for keywords inside files. Then return the file paths in a variable. (Each file path separated with \n). #!/bin/bash SEARCHQUERY="searchword1 searchword2 searchword3"; for WORD in $SEARCHQUERY do ... (6 Replies)
Discussion started by: limmer
6 Replies
Login or Register to Ask a Question