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?


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.

| 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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