Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Alternative line numbering for each file.

  • Loading branch information...
commit 27c29a0c61db43c6819944228e85c3cb5256b983 1 parent 6edf434
@KL-7 authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 ruby-one-liners/Readme.md
View
5 ruby-one-liners/Readme.md
@@ -17,6 +17,11 @@ for each of these tasks:
# (also, 1.9 only)
ruby -e 'l=-> line {puts "#$. #{line}"}; ARGV.each { |name| File.foreach name, &l}; $stdin.each &l'
+ # alternative version
+ # $<.pos, that is ARGF#pos, returns position (in bytes) in the current file
+ # that allows us to reset $. at the end of the first line of each file
+ ruby -ne '$. = 1 if $<.pos - $_.size == 0; puts "#$. #$_"'
+
### add line numbers for all files together
Please sign in to comment.
Something went wrong with that request. Please try again.