It is currently Tue, 17 May 2022 18:12:18 GMT



 
Author Message
 How Can I OverWrite Output?
My simple script counts files, descending from the directory pointed to.
No error checks yet, just filling in the concept:

#!/bin/bash2
count=0;
for file in `find $1 -type f`; do ((count+=1)); done
printf "   This is how many files there are \n      in directory $1:
                                  $count\n";
exit 0

I would like, for grins and giggles, to output the count as it is
incremented (I use this to size up directory trees with very many files,
and it takes a while to run, it would be useful to be able to look in and
check progress.)  I would like to print the current $count to screen after
the prompt, each time it's incremented.  This should overwrite the last
output of $count rather than linefeed+output+linefeed+output or
outputoutputoutput as with use of echo $count or printf $count.

I saw this done with a shell script that had a rotating bar sequence:
/-\-|-/-\-|   something like that.  Can this be done?  Thanks for your
input,             /ts

              tenox  @  home  dot   com



 Tue, 03 Jun 2003 13:37:11 GMT   
 How Can I OverWrite Output?
In article <3a39ab28.51806599@news>,

printf "   This is how many files there are \n      in directory %s:\n" $1
for file in `find $1 -type f`; do ((count+=1))
  printf "    %d\r" $count
done
printf "\n"
exit 0

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Wed, 04 Jun 2003 08:33:57 GMT   
 How Can I OverWrite Output?
It was: Sat, 16 Dec 2000 00:33:57 GMT  and with STARTLING insight,  "Barry
Margolin <bar...@genuity.net>"   posted "Re: How Can I OverWrite Output?"
 to "comp.unix.shell" :

-->>I would like, for grins and giggles, to output the count as it is
-->>incremented (I use this to size up directory trees with very many files,
-->>and it takes a while to run, it would be useful to be able to look in and
-->>check progress.)  I would like to print the current $count to screen after
-->>the prompt, each time it's incremented.  This should overwrite the last
-->>output of $count rather than linefeed+output+linefeed+output or
-->>outputoutputoutput as with use of echo $count or printf $count.
-->
-->printf "   This is how many files there are \n      in directory %s:\n" $1
-->for file in `find $1 -type f`; do ((count+=1))
-->  printf "    %d\r" $count
-->done
-->printf "\n"
-->exit 0

-->Barry Margolin, bar...@genuity.net

That's great, thank you.  The script runs for a long time before beginning
to output the count.  What happens?  Is the find command completing its
finding task first then parsing for files of -type f?  Would a proper use
of ls (list command) be synched better, cleaner in concept, er, uh, use
less resources?
I'm going to try this out.  And again, thanks for the working solution!    

/ts ------> [have a happy season!]

              tenox  @  home  dot   com

       [WARNING: stand clear of suspended loads]



 Wed, 04 Jun 2003 12:44:10 GMT   
 How Can I OverWrite Output?
In article <3a3af2cc.43877475@news>,

Yes, it's waiting for find to complete, since it has to substitute all its
output for the `...` expression.  To avoid that, you can do:

find $1 -type f | while read file; do
 ...
done

This will process each file as it's output by find.

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Thu, 05 Jun 2003 14:34:23 GMT   
 
   [ 4 post ] 

Similar Threads

1. Change ps output by overwriting argv[0]

2. Overwriting argv from within a process to affect ps output

3. PPPD or Tin Cans: Which is Better?

4. Any Canned Class code?

5. It's not bad canned meat...

6. Canned "ping"

7. CGI: apache canned response

8. Canned Proxy URLs to Filter

9. For those of you tired of canned distributions...

10. OT: Canning: Another advancement due to Napolean


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software