You are not logged in.
The topic pretty much says it. I've built a script that reads various settings and then loops every few seconds. The script works well but I'd like to instead of writing to newline to have the new output replace the line of last output. The script is real basic and is something like this:
while true; do
grep "something" filename | cut -d " " -f 3
sleep 5
done
I was wondering if anyone knew how to replace the last line when the new output arrives.
Last edited by Gen2ly (2010-04-09 23:31:08)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
'sed -i' or '>' if it's the only line.
Edit: How do you read the output file? Maybe 'tail -1' would help? It reads only the last line, so appending the new line to the end of the file would be OK. You can then periodically remove the "history" file.
Last edited by karol (2010-04-09 07:03:56)
Offline
If I understand correctly what you want to do, you might consider using 'watch'.
See 'man watch' for details.
Offline
Do you mean like an updating message on the terminal? You can do that sort of thing using escape codes and ANSI terminal escape sequences, I think. Is this example helpful?
for ((i=0;i<10;i++)); do
echo -n $i
sleep 1
echo -ne "\x0d\E[2K"
done
Last edited by Bralkein (2010-04-09 11:40:31)
Offline
The escape codes does it: clears the line before the next input. Nice work, Bralkein. Thank you.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Offline
Huh, interesting. Hadn't thought about using tput. The escape codes are working good for me now, but this is good reference for the future. Thanks, Profjim.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
tput is a lot slower than echo ESC, though.
Offline
tput is a lot slower than echo ESC, though.
Yeah, that's the price of portability for different terminals. You have to decide whether it's worth it.
Even if you decide it's not worth it, it's good to know about tput so that you can interactively query the codes recognized by your own terminal (well, at least, according to its terminfo entry, which may not always be 100% accurate).
Or you could query just once for each of the relevant codes, and save it in a bash variable.
Last edited by Profjim (2010-04-10 14:07:46)
Offline