Created
December 4, 2020 06:06
-
-
Save mattk42/e03122547db92504810b96bf454c7a37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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