If you used 'su' then you did not sudo. Anyway... for parsing a file, suggest you read through
12 ways to parse a file. That should be a good start. Then regarding storing a variable in a file, go through the man page of any shell (sh/bash/ksh) and search for redirection. That will help too.