How do I delete a saved wifi network, when unable to use the Network panel/GUI in System pref? I need to delete a saved public wifi network, which my computer keeps trying to connect to when I'm at home, but I can't open my Network preferences and do it trough the GUI, due to an error in my MacOS installation (see linked question below for details).

I'm guessing there might be a way to do it, through Terminal or digging into a .plist, but haven't been able to find any non-GUI guides to this through searching, so how can this be done?

Why does my Network preference pane freeze every time I open it?

System info:
MacBook Pro (Retina, 15-inch, Mid 2015)
MacOS Sierra 10.12.6 (16G29)
You can check the list of preferred networks with the command: 

sudo networksetup -listpreferredwirelessnetworks en1

You can then copy the name of the wifi you want to remove from the list and use the command (replacing wifi_to_be_removed with the name of the wifi):

sudo networksetup -removepreferredwirelessnetwork en1 wifi_to_be_removed

Note: en1 is usually the device name of the single wifi card in a mac that also has a ethernet port. To be sure of the device name use the command: sudo networksetup -listallhardwareports
to list the various network devices and their denomination.