I'm kinda new to the $read and /write commands and I'm trying to find a way to remove a variable line number. Basically I have the /write command write your *!*@host or known as $address($nick,2) to a text file. Now I have

if $read(masks.txt, w, $address($nick,2)) == $address($nick,2) {

in this part of my file I want it to now delete the matching entry. I know $readn returns the line number but I cant seem to get it to be useful in the /write command. The only thing I got it to delete so far was the first line no matter what it is.
So far I have tried
/write -dl$readn masks.txt
/write -dw$readn masks.txt
/write -ds$address($nick,2) masks.txt

I know there has to be a way to get this to work. I also have tried the same after setting a variable to $readn and the variable is being set to the right line number, just not working in /write. I just dont want to have to make it

If ($readn == 1) {
/write -dl1 masks.txt
}
If ($readn ==2) {
/write -dl2 masks.txt
}

and so on... since theres going to be a whole ton of lines in this text file.