Skip to content

Instantly share code, notes, and snippets.

@tijn
Created May 4, 2012 11:33
Show Gist options
  • Save tijn/2594261 to your computer and use it in GitHub Desktop.
Save tijn/2594261 to your computer and use it in GitHub Desktop.
script to delete one line from a file, uses input like this: ~/.ssh/known_hosts:60
#!/usr/bin/env ruby
# script to delete one line from a file
# because remembering how sed works is too hard
# Tijn Schuurmans - May 4, 2012
def print_usage
puts <<-end_usage_description
delete_line
delete one line from a file
Usage:
delete_line FILE:NUMBER
Example:
delete_line ~/.ssh/known_hosts:60
end_usage_description
end
if ARGV.empty?
print_usage
exit
end
filename, line_number = ARGV.last.split(':')
raise "No such file #{filename}" unless File.file?(filename)
raise "I need a line number" if line_number.nil? || line_number.empty?
`sed -i '#{line_number} d' #{filename}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment