-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved line for piped input. Added trim, a special case of line.
- Loading branch information
1 parent
d6ab0ee
commit 98c2960
Showing
2 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
#!/usr/bin/env ruby | |||
# Author: Joseph Pecoraro | |||
# Date: Saturday April 4, 2009 | |||
# Description: Opposite of Head. | |||
# Removes the first -n lines. | |||
|
|||
# Line to trim up to | |||
limit = 0 | |||
|
|||
# Get a Command line Limit | |||
ARGV.each do |arg| | |||
if matches = arg.match( /^-(\d+)$/ ) | |||
limit = matches[1].to_i | |||
end | |||
end | |||
|
|||
|
|||
# Remove Command Line Args | |||
ARGV.delete_if { |arg| arg.match(/^-\d+$/) } | |||
|
|||
# Print Lines from STDIN | |||
if ARGV.size == 0 | |||
|
|||
# Skip Lines | |||
while limit > 0 | |||
limit -= 1 | |||
gets | |||
end | |||
|
|||
# Print Loop | |||
while ( line = gets ) | |||
puts line | |||
end | |||
|
|||
# Print Lines from a File | |||
else | |||
|
|||
ARGV.each do |filename| | |||
lines = File.readlines(filename) | |||
lines.slice!(0, limit) | |||
lines.each { |l| puts l } | |||
end | |||
|
|||
end |