Skip to content

Instantly share code, notes, and snippets.

@vhata
Last active December 3, 2021 21: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 vhata/da8144716c1a054f11f5830f02058a1d to your computer and use it in GitHub Desktop.
Save vhata/da8144716c1a054f11f5830f02058a1d to your computer and use it in GitHub Desktop.
#!/opt/homebrew/bin/bash
INPFILE=day3.txt
cp $INPFILE oday3s1.txt
cp $INPFILE cday3s1.txt
echo -n '^' > opatfile
echo -n '^' > cpatfile
len="$(($(head -n1 $INPFILE | wc -c) - 1))"
for z in $(seq 1 $len) ; do
owanted=$(cat oday3s${z}.txt | cut -c${z} | sort | uniq -c | sort -n | tail -n1 | awk '{print $2}')
cwanted=$(cat cday3s${z}.txt | cut -c${z} | sort | uniq -c | sort -rn | tail -n1 | awk '{print $2}')
echo -n "$owanted" >> opatfile
echo -n "$cwanted" >> cpatfile
egrep -f opatfile oday3s${z}.txt > oday3s$(($z + 1)).txt
egrep -f cpatfile cday3s${z}.txt > cday3s$(($z + 1)).txt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment