Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

when i execute the following line, its prints the words in newline. awk 'BEGIN { print "line one\nline two\nline three" }' like line one line two line three

How can i print the info in the same line with flush the existing line. For example, while executing the loop, it should print 'one' then wipe out the line and prints 'two' then wipe out the line and prints 'three' etc. can you please assist me?

share|improve this question

2 Answers 2

Use carriage return instead of newline

awk 'BEGIN { print "line one\rline two\rline three" }' 

If a subsequent line is shorter than a previous line, you can print spaces to wipe out the remainder:

awk 'BEGIN { print "this is a long line of text\rpad with spaces            " }' 

If you are using separate statements, then you should use printf instead of print.

share|improve this answer

What environment are you using to view your output? Putty? You may need to reconfigure Putty to honor \n "newLines". OR if your really in Windows/DOS mode, you need

printf "line 1\r\nline 2\r\nline 3\r\n"

Hope this helps.

As you're a new user, just a gentle reminder to accept the answer that works for you, or at least add a vote to answers that help you're understanding.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.