<p>First of all get rid of all that junk. One priv key per line is all you need. So use <code>grep privkey filename|cut -d":" -f2 &gt; clean-file.txt</code>. Then call this  python script with that file as an argument:</p>

<pre><code>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)
</code></pre>

<p>It'll output all the private keys in the various formats. </p>

CC BY-SA 4.0
2019-04-13T17:19:08.683Z
2019-04-13T17:29:52.367Z
2019-04-13T17:29:52.367Z
Abdussamad
<p>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)</p>

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

<p>The file is in format:  </p>

<pre><code>BTC Pattern: &lt;pattern&gt;  
BTC Address: &lt;bitcoin address beginning with one&gt;  
BTC Privkey: &lt;bitcoin address beginning with five&gt;
...
</code></pre>

CC BY-SA 4.0
2019-04-12T23:34:57.190Z
Does [this](http://docs.electrum.org/en/latest/faq.html#can-i-import-private-keys-from-other-bitcoin-clients) help?
Mason Ticehurst
CC BY-SA 4.0
2019-04-12T23:40:10.763Z
@KappaDev Thank you, I can filter my input file and paste a bunch. Updated question for derivable addresses.
user93729
<electrum><script><private-key-import><import><electrum-console>
Script to import multiple priv keys in Electrum
user93729
# Script to import multiple priv keys in Electrum

(Asked by: username_0 on 2019-04-12)

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:   
BTC Address:   
BTC Privkey: 
...

**Tags:** electrum, script, private-key-import, import, electrum-console

> **Comments:**
> **username_1**: Does [this](http://docs.electrum.org/en/latest/faq.html#can-i-import-private-keys-from-other-bitcoin-clients) help?  
> **username_0**: @KappaDev Thank you, I can filter my input file and paste a bunch. Updated question for derivable addresses.  

---

## 1 answers

### Answer by username_2 on 2019-04-13. Score: 1

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 > 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.


---

