Update single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Update single line
# 1  
Old 05-28-2011
Update single line

Hi everyone

i need one help don't know whether it is simple or difficult but not able to solve it.
here is the problem

suppose my code is

Code:
 
time_def=3
r=0
while [[ $r -lt ${time_def} ]]
do
echo "time left is $time_def "
((time_def=time_def-1))
done
 
and the output is
time left is 3
time left is 2
time left is 2

can we make the output in one line so that each time it does not echo the statement like

Code:
 
time left is 3

then instead of diaplaying "time left is 2" it display on the same line "time left is 2"

please help me in this

---------- Post updated at 10:51 AM ---------- Previous update was at 08:28 AM ----------

to be in simple language i want to display changing of time in only one line not in multiple lines.

can we do this?/
# 2  
Old 05-28-2011
I suppose your script to be in bash, so
Position of the cursor in bash
Code:
echo -ne '\033[s\033[10;1HHello World\033[u'

See more there: Cursor Movement
# 3  
Old 05-28-2011
@above
can u please explain the solution
yes the script is in bash
but the line which i want to update should be in single line..
# 4  
Old 05-28-2011
The escape character \033[line;columnH allows you to set cursor position before writing actual text. -e option on echo tells bash that echo needs to parse escapes sequences.
Others escapes sequences can be found on the link in my previous post.
# 5  
Old 05-29-2011
@above
thanks for ur reply...
but can u please elaborate in real time scenario like which i gave ...
because i have to implement that functionlity in my code...
please if u have time , can u tell me how to do this in above codel..
thanks in advance..
# 6  
Old 05-29-2011
Code:
#!/bin/bash

time_def=3
r=0
echo
while ((r<time_def)); do
    echo -e "\033[1Atime left is $time_def"
    ((time_def--))
    sleep 1
done

exit 0

# 7  
Old 05-30-2011
@above
thank u very much it works
thanks again Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

5. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Solaris

Update single zone in alternate boot environment.

I 'm having a weired situation my system has 8 zones, running fine on solaris x86_u4. I installed the live upgrade bundle patch and did a live upgrade. The new BE was created but it missed one of the zone and now if i mount the new BE i do not see that zone in the environment so my question is how... (3 Replies)
Discussion started by: fugitive
3 Replies

8. Red Hat

How to update all rpms using single command option

Can any one help me to know the command option that will update all rpms Thanks in advance.. (2 Replies)
Discussion started by: RajendraKumar
2 Replies

9. Solaris

patch update with single user mode

Hi All, How do I execute patch update on a single user mode? Please give me the steps by step procedures? Is single user mode the same as run level 1? Thanks. (2 Replies)
Discussion started by: itik
2 Replies

10. Shell Programming and Scripting

How to update a single row in a file with sed

Hi. I want to be able to update only one line in a file that matches a key using sed, but I can't seem to get this (the key is right at the beginning of each row) Here is what I have tried so far, but every row is being updated. I want the end result to be that the input file only has the single... (6 Replies)
Discussion started by: brendanf
6 Replies
Login or Register to Ask a Question