$2 == "ls" || $1 == "dir" { next} $2 == "cd" && $3 != ".." { depth += 1 l = "" for (i=1;i", S[depth] S[depth]=0 depth -= 1 } # part 1 # awk -f print.awk input | grep -F '=>' | awk 'NF>2 && $(NF)>(100*1000)' | awk '{ print $NF }' | sum0 # part 2 # TOTAL 70'000'000 # UPDATE 30'000'000 # ROOT 43'837'783 # FREE 26'162'217 # NEED 3'837'783 # list all sizes # awk -f print.awk input | grep -F '=>' | awk 'NF>2 && $(NF)>(100*1000)' | awk '{ print $NF }' | sort -n # find number at the bottom of the list that is >=NEED # ... # 2882941 # 3572786 # 3718312 <= too low # 4183246 <= this one # 5406295 # 5928595 # ...