You can achieve that using any script language that knows hashes/dictionaries/associative arrays/whatever it calls the feature.
A very very very simple approach would be like this:
$> cat File1 johndoe janedoe nosuchkid $> cat File2 johndoe@email.com janedoe@email.com $> awk -F'@' 'FILENAME=="File2" { emails[$1]=$0; next}; { print ($1 in emails) ? $1 : "# "$1}' File2 File1 johndoe janedoe # nosuchkid
Probably, you can see that this one does not modify anything in the input files just writes stdout.
EDIT: Redirecting the output into a file and renaming that would appear as changes in the original file called File1 here (making a backup of the original file is always a good idea):
$> awk -F'@' 'FILENAME=="File2" { emails[$1]=$0; next}; { print ($1 in emails) ? $1 : "# "$1}' File2 File1 > File1.tmp ; cp File1 File1.old ; mv File1.tmp File1 $> cat File1 johndoe janedoe # nosuchkid
EDIT2: Let's be a little less literal:
$> export PERSONFILE=File1 EMAILFILE=File2; awk -F'@' 'FILENAME==ENVIRON["EMAILFILE"] { emails[$1]=$0; next}; { print ($1 in emails) ? $1 : "# "$1}' "$EMAILFILE" "$PERSONFILE" > "$PERSONFILE.tmp" ; cp "$PERSONFILE" "$PERSONFILE.old" ; mv "$PERSONFILE.tmp" "$PERSONFILE"