Skip to content

Instantly share code, notes, and snippets.

@Dan-Q
Created September 4, 2020 18:30
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 Dan-Q/311b032948189bf297da33e00dd62cc1 to your computer and use it in GitHub Desktop.
Save Dan-Q/311b032948189bf297da33e00dd62cc1 to your computer and use it in GitHub Desktop.
Split GPX files generated by GPSBabel based on Google Takeout "My Location" KML into multiple months
INPUT = "Google Maps Location History.gpx"
OUTPUT_PREFIX = "Result"
START_YEAR = 2013
(START_YEAR..Time.now.year).each do |year|
(1..12).each do |month|
long_month = sprintf('%02d', month)
puts filename = "#{OUTPUT_PREFIX} #{year}-#{long_month}.gpx"
`head -n5 "#{INPUT}" > "#{filename}"`
`grep -B2 -A1 "<time>#{year}-#{long_month}" "#{INPUT}" >> "#{filename}"`
`tail -n3 "#{INPUT}" >> "#{filename}"`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment