Depending on the version of macOS, and where the file is located will depend if this can be done.
There are 2 ways to do this.
1st, and the easiest is to open the file in a text editor and after you make your changes do a Save As and save the file to your Desktop. Then drag the new file to the location of the old file. If its not on a read only volume (in Big Sur or later), then you will be prompted for your admin password, and you can then overwrite the old file with the new one.
The second option is to right click on the file and select Get Info. (Or highlight the file and hit Command I), ane then in the Get Info scroll all the way down to the bottom. Click on the lock and enter your Admin password. Then you can change the permissions. Again, depending on the versin of macOS, If the file in on a read only volume then you may not be able to change the permissions.