Skip to content

Instantly share code, notes, and snippets.

@acarrillo
Created August 2, 2012 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acarrillo/3241127 to your computer and use it in GitHub Desktop.
Save acarrillo/3241127 to your computer and use it in GitHub Desktop.
A filter for converting timestamps to a more readable date format
#!/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
@acarrillo
Copy link
Author

@kevinwang -- again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment