Posts

Showing posts from April, 2009
Just running a test!







showhide

Real's HowTo

Textmate Ruby Macro Remove Blank Lines

Textmate Ruby Macro Remove Blank Lines
#!/usr/bin/env ruby -wKU
STDIN.readlines.each {|e| print e unless e =~ /^\n/}

#Set Save "Nothing"
#Set Input "Selected Text" or "Character"
# and
#Set Output "Replace Selected Text"

Textmate Ruby Macro Comma Separated List to Line

Textmate Ruby Macro Comma Separated List to Line
#!/usr/bin/env ruby -wKU
STDIN.read.split(",").each {|e| print e+"\n"}

#Set Save "Nothing"
#Set Input "Selected Text" or "Character"
# and
#Set Output "Replace Selected Text"

Textmate Ruby Macro Lines to Comma Separated List

Lines to Comma Separated List
#!/usr/bin/env ruby -wKU
STDIN.readlines.each {|e| print e.gsub(/\n/,",")}
print "\n"

#Set Save "Nothing"
#Set Input "Selected Text" or "Character"
# and
#Set Output "Replace Selected Text"
Looks useful thanks David Thomas
Original Link

HANDY ONE-LINERS FOR RUBY November 16, 2005
compiled by David P Thomas version 1.0

Latest version of this file can be found at:
http://www.fepus.net/ruby1line.txt

Last Updated: Wed Nov 16 08:35:02 CST 2005

FILE SPACING:

# double space a file
$ ruby -pe 'puts' < file.txt
# triple space a file
$ ruby -pe '2.times {puts}' < file.txt
# undo double-spacing (w/ and w/o whitespace in lines)
$ ruby -lne 'BEGIN{$/="\n\n"}; puts $_' < file.txt
$ ruby -ne 'BEGIN{$/="\n\n"}; puts $_.chomp' < file.txt
$ ruby -e 'puts STDIN.readlines.to_s.gsub(/\n\n/, "\n")' < file.txt

NUMBERING:

# number each line of a file (left justified).
$ ruby -ne 'printf("%-6s%s", $., $_)' < file.txt
# number each line of a file (right justified).
$ ruby -ne 'printf("%6s%s", $., $_)' < file.txt
# number each…