Created
August 2, 2012 22:08
-
-
Save acarrillo/3241127 to your computer and use it in GitHub Desktop.
A filter for converting timestamps to a more readable date format
This file contains hidden or 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 | |
# | |
# Authors: Kevin Wang and Alex Carrillo | |
# Description: Replaces UNIX timestamps with more human-friendy strings | |
# | |
# Make this file executable with `chmod +x datefiltr.rb` and put it in your path. | |
# | |
# Example usage: | |
# $ datefiltr.rb < file-with-timestamps.txt > file-with-readable-dates.txt | |
# | |
# Or | |
# $ cat file-with-timestamps.csv | datefiltr.rb > output.csv | |
# | |
# | |
require 'date' | |
while STDIN.gets | |
a = $_ | |
a = a.sub /[0-9]{10}/ do |match| DateTime.strptime(match, '%s').strftime("%c") end while (a =~ /[0-9]{10}/) != nil | |
print a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kevinwang -- again.