I'm not going to go through it all, but here is those two lines with ONLY the bracket/brace/pipe fixes

if ($did = 13) { if (%identd = Off) { did -u perstg 13 | .set %ident Off } | else { did -c perstg 13 | .set %ident On } }

if (%identd = On) { did -c perstg 13 | .identd on %id } | else { did -u perstg 13 | .identd off }