Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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