Skip to content

Instantly share code, notes, and snippets.

Avatar
💼
On Leave until July

Andrew Battista andrewbattista

💼
On Leave until July
View GitHub Profile
@andrewbattista
andrewbattista / exec-cat-js.md
Created Sep 8, 2020
Concatenate many JSON files into single JSON file with JS
View exec-cat-js.md

If you have a directory path with many JSON files in it and you want them all on a single document for batch edits use JS

find . -name '*.json' -exec cat '{}' + | jq -s '.' > /Users/staff/Desktop/newjsonsinglefile.json

To reduce the process time for exceedingly large examples, you may be able to simply use

find . -name '*.json' -exec jq -s '{}' + > /Users/staff/Desktop/newjsonsinglefile.json
@andrewbattista
andrewbattista / pull-invenio-records.md
Last active Sep 17, 2020
Pull all records from invenio and pretty print them
View pull-invenio-records.md

Pull all records from invenio

Use this bash script and command to pull down all records from invenio and save them as discrete files within uniquely named directories

Create a file named invenio_recs.sh with these contents:

#!/bin/bash

#create directory for records
@andrewbattista
andrewbattista / grep-get-coordinates.md
Created Jul 13, 2020
Recursive extraction of coordinates from .JPG files
View grep-get-coordinates.md

Use grep to strip out elements from photo metadata

If you have a bunch of .jpg photos in a directory that were taken with a camera with coordinates associated, this workflow will allow you to recursively get the coordinates.

First, install exiftool Then, from the directory where all of the .JPGs are

exiftool /Users/andrewbattista/desktop/*.JPG |grep 'File Name\|GPS Latitude\|GPS Longitude'
@andrewbattista
andrewbattista / recursive-conversion-gdal.md
Last active Jul 2, 2020
Recursive conversion between formats with GDAL
View recursive-conversion-gdal.md

Recursive conversion with GDAL

This shell script assumes that you have already installed GDAL and are converting between .KMZ files and Shapefiles with the names preserved. The specific ogr2ogr commands can be changed as needed. This also assumes many .KMZ files in a single directory. Kudos to Marii Nyrop.

Begin by creating a file named batch-separate-folders.sh with the following and place it in your directory with the KMZs:

for KMZ in *.kmz; do
  IDENTIFIER="$(basename ${KMZ} .kmz)"
@andrewbattista
andrewbattista / zip-files.md
Last active May 4, 2020
Zip all files in a directory and rename
View zip-files.md

Zips all files within a containing directory

This zips all files in a directory and renames the zip archive according to the name of the existing directory.

for i in */; do zip -r "${i%/}.zip" "$i"; done