Created
May 4, 2012 11:33
-
-
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
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
#!/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