From: Sean O'Dell Date: 2004-07-03T02:03:28+09:00 Subject: Re: Help with one-liner On Friday 02 July 2004 09:41, Philip Mateescu wrote: > You're probably right about the line ending, here's a variation: > > $ ping localhost | ruby -e '$<.each_line { |line| chomp1 = line.chomp(); > chomp_rn = line.chomp("\r\n"); chomp_r = line.chomp("\r"); chomp_n = > line.chomp("\n"); puts chomp1 + "-- 1--"; puts chomp_rn + "--rn--"; puts > chomp_r + "-- r--"; puts chomp_n + "-- n--"; }' > > And the result: > -- 1--from 127.0.0.1: bytes=32 time<1ms TTL=128 > --rn--from 127.0.0.1: bytes=32 time<1ms TTL=128 > Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 > -- r-- > -- n--from 127.0.0.1: bytes=32 time<1ms TTL=128 > > Baffling.... Just remember what \r does. In your original code, if \r appeared at the end of each line, the line would print, then \r would return the cursor to the beginning of the same line, then --- would print, then \n would cause a newline break. Change your code to: $ ping localhost | ruby -e '$<.readlines.each { |line| �line.chomp!(); p (line + "---\n"); �}' ...and you'll be able to see the special characters escaped. Sean O'Dell