Skip to content

Instantly share code, notes, and snippets.

@mattk42
Created December 4, 2020 06:06
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 mattk42/e03122547db92504810b96bf454c7a37 to your computer and use it in GitHub Desktop.
Save mattk42/e03122547db92504810b96bf454c7a37 to your computer and use it in GitHub Desktop.
#!/bin/bash
required_fields="byr iyr eyr hgt hcl ecl pid"
while read line
do
# read through until blank line or end of file to capture a full passport
if [ -z "$line" ]
then
for field in $required_fields
do
exists=$(echo $passport | grep -c "$field:")
if [ $exists -eq 0 ]
then
invalid=$(($invalid+1))
missing="$missing $field"
continue
fi
done
if [ "{$missing}" == "{}" ]
then
valid=$(($valid + 1))
fi
missing=""
passport=""
continue
fi
passport="$passport $line"
done <<< $(<$1)
echo $valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment