Skip to content

Instantly share code, notes, and snippets.

@ivyleavedtoadflax
Created August 6, 2019 15:19
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 ivyleavedtoadflax/0993058ed2b25d93042219da602706bd to your computer and use it in GitHub Desktop.
Save ivyleavedtoadflax/0993058ed2b25d93042219da602706bd to your computer and use it in GitHub Desktop.
Iterate through a bash file and do some things
for i in raw/*.json;
do
# Create new filename
filename=$(basename -- "$i")
extension="${filename##*.}"
filename="${filename%.*}"
new_filename=processed/refs_${filename}.txt
# Shuffle the first 1000 rows, and extract the reference sections
# then save as a new file.
cat $i | shuf | head -n 1000 | jq .sections.Reference > ${new_filename}
# Remove all the null values created by jq
sed /^null$/d -i ${new_filename}
echo "Output ${new_filename}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment