# "puts" without line feed

**URL:** <https://www.ruby-forum.com/t/puts-without-line-feed/145494>\
**Category:** Ruby\
**Created:** [August 10, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494 "2008-08-10T20:38:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/1 "2008-08-10T20:38:19Z")

</div>

Hi,  
Is there a way to show output on a single line in the command prompt,  
overwriting each time instead of linefeeding everytime I puts ‘my data’  
?

I want the appearance of progress thru numerous iterations without  
scrollin off into oblivion.

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/2 "2008-08-10T20:42:24Z")

</div>

it’s “print”

print “line without line-feed”

or was it “prints” i don’t remember.

-Patrick

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/3 "2008-08-10T20:44:26Z")

</div>

On Sun, Aug 10, 2008 at 2:36 PM, Bob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> Is there a way to show output on a single line in the command prompt,  
> overwriting each time instead of linefeeding everytime I puts ‘my data’  
> ?
> 
> I want the appearance of progress thru numerous iterations without  
> scrollin off into oblivion.

try print instead of puts

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 8:45pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/4 "2008-08-10T20:45:36Z")

</div>

Heya!

On Sun, Aug 10, 2008 at 8:36 PM, Bob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> Is there a way to show output on a single line in the command prompt,  
> overwriting each time instead of linefeeding everytime I puts ‘my data’  
> ?

You can use print() instead of puts() which doesn’t add a linefeed.

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/5 "2008-08-10T21:13:07Z")

</div>

Bob M. wrote:

> Is there a way to show output on a single line in the command prompt,  
> overwriting each time instead of linefeeding everytime I puts ‘my data’  
> ?

$stdout.sync = true  
5.times do |i|  
print “\r#{i}”  
sleep 1  
end

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/6 "2008-08-10T21:55:50Z")

</div>

Bob M. wrote:

> then  
> does what I want at all, eh?  
> Thanks for kind & timely responses.

Try Sebastian’s example. It does what you want.

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/7 "2008-08-10T23:10:45Z")

</div>

Le 10 août 2008 à 21:27, Bob M. a écrit :

> so it rolls along “in place”

Try writing a “backspace” control caracter (ctrl-h, ascii code 8) ; for  
example :

print “Countdown : 9”  
9.downto(0) do |x|  
print “\C-h#{x}”  
sleep 1  
end  
puts

(I’m not entirely sure it’s completely cross-platform, but this simple  
example works well with Windows and Unixoïds.)

Fred

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 11, 2008, 12:22am UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/8 "2008-08-11T00:22:10Z")

</div>

On Mon Aug 11 04:27:56 2008, Bob M. wrote:

> then  
> does what I want at all, eh?  
> Thanks for kind & timely responses.

You need to flush $stdout and move to the beginning of the line each  
time:

jump = “\r\e[0K” # That is return to beginning of line and use the  
# ANSI clear command “\e” or “\003”

(1…10).each do |i|  
print jump + i  
sleep 1  
$stdout.flush  
end

That should sort you.

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [August 10, 2008, 9:30pm UTC](https://www.ruby-forum.com/t/puts-without-line-feed/145494/9 "2008-08-10T21:30:11Z")

</div>

uze guyz are SO close.

Print gives me

123456…_to a new line_…_to another new line_…

I’m tryin for

1

then

2 (where 1 was)

then

3 (where 1, then 2 were)

so it rolls along “in place”

Kinda silly, I know…I guess I should be happy the darn thing runs &  
does what I want at all, eh?  
Thanks for kind & timely responses.
