Script to import multiple priv keys in Electrum DuckDuckGo turns up nothing of interest. How to import multiple priv keys in Electrum from a file using Electrum console or shell script, for all derivable valid BTC addresses? (1,3,bc1)

Eventually I would like to pipe the output of one script directly into an import script.

The file is in format:  

BTC Pattern: &lt;pattern&gt;  
BTC Address: &lt;bitcoin address beginning with one&gt;  
BTC Privkey: &lt;bitcoin address beginning with five&gt;
...
First of all get rid of all that junk. One priv key per line is all you need. So use grep privkey filename|cut -d":" -f2 &gt; clean-file.txt. Then call this  python script with that file as an argument:

import sys
from electrum import bitcoin
f = open(sys.argv[1], "r")
for privkey in f:
    privkey=privkey.strip()
    orig_format,secret,compressed=bitcoin.deserialize_privkey( privkey)
    formats = [ bitcoin.serialize_privkey( secret, False, "p2pkh"), bitcoin.serialize_privkey( secret, True, "p2pkh"), bitcoin.serialize_privkey( secret, True, "p2wpkh"), bitcoin.serialize_privkey( secret, True, "p2wpkh-p2sh") ]
    for thing in formats:
        print(thing)


It'll output all the private keys in the various formats.