LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Printing a new file over the old file using cat (https://www.linuxquestions.org/questions/programming-9/printing-a-new-file-over-the-old-file-using-cat-340669/)

mrobertson 07-06-2005 01:33 PM

Printing a new file over the old file using cat
 
I have a script running that will read and print out this file. Right now I am using the following code:


Code:

#!/bin/sh
while sleep 1
      do
            cat camdata
done




And this code will print it out each time over and over again taking up multiple lines. The file is four lines of text. Is there anyway to just print the 4 lines and then when it comes time to print again....just print over the previous four lines so that there is always only 4 lines of text printed instead of 4 then 8 then 12 then 16.....etc?

jim mcnamara 07-06-2005 01:58 PM

Use redirection
Code:

#!/bin/sh
while sleep 1
      do
            cat camdata > camdatafile
done

But you have one second to se what's in the camdatafile

ahh 07-06-2005 02:16 PM

I thnk the simplest solution is:-

Code:

#!/bin/sh
while sleep 1
      do
            clear
            cat camdata
done


mrobertson 07-07-2005 07:14 AM

I tried adding clear like the last post suggested and got a "clear not found error." I also tried using the redirection approach suggested and got no output whatsoever. Is there any other way that this task could be done?

ahh 07-07-2005 10:18 AM

Try typing "which clear" in your terminal to see if you have clear on your system - it should be there. If it is add the full path to your script.
Code:

#!/bin/sh
while sleep 1
      do
            /usr/bin/clear
            cat camdata
done

The redirection is writing the contents of camdata to camdatafile. You are basically making a copy of camdata.


All times are GMT -5. The time now is 08:33 PM.