user27: I am testing some new code, and need to sort the output of listtransactions. Ultimately I need to verify that there are no duplicate txids.
How do I output  ./bitcoind -datadir=1 listtransactions "*" to a logfile, or sort it directly in the terminal window?

user22: I don't believe bitcoind has any kind of a sort option. The output of bitcoind listtransactions is in chronological order, but the output of your command could be written to a text file and parsed by any number of simple scripts. I don't have one offhand but the output is in JSON which most languages (including Python, my favorite) handle quite nicely. Once you bring the JSON data in it should be a simple matter of sorting the transactions array.
Edit: Depending on what data you're trying to extract and in what format, you may be able to do something with Gavin Andresen's bitcointools scripts.

user5: I am not sure what you mean by sorting, but here is a little python script to check for duplicate txid's:
import json
from sys import argv, stdin

file = stdin.read() #reads transaction list from input
json_file = json.loads(file)

#counts the number of duplicate txid's
txid_list = [transaction["txid"] for transaction in json_file]
print "There are", len(txid_list) - len(set(txid_list)), "duplicates"

Let's suppose that you save this to a file named check_duplicates.py. Now you just need to output the transactions to a file and feed it to the script:
$ ./bitcoind -datadir=1 listtransactions "*" > transactions.log
$ python check_duplicates.py < transactions.log
There are N duplicates

Depending on what you need, other sorting operations can be done. It's easy to manage json with python.

user53: You can run the listtransaction JSON output through this little python script (save it as jsonTOCSV.py). That will produce csv (comma separated value) output that Excel or Google Spreadsheets can import, both of which can sort by columns (if I recall correctly).
So:

bitcoind listtransactions | jsonTOCSV.py > transactions.csv

#!/usr/bin/env python
#
# Reads an array of JSON objects and writes out CSV-format,
# with key names in first row.
# Columns will be union of all keys in the objects.
#

import csv
import json
import sys

json_string = sys.stdin.read()
json_array = json.loads(json_string)

columns = set()
for item in json_array:
  columns.update(set(item))

writer = csv.writer(sys.stdout)
writer.writerow(list(columns))
for item in json_array:
  row = []
  for c in columns:
    if c in item: row.append(str(item[c]))
    else: row.append('')
  writer.writerow(row)


27: <p>I am testing some new code, and need to sort the output of listtransactions. Ultimately I need to verify that there are no duplicate txids.</p>

<p>How do I output  <code>./bitcoind -datadir=1 listtransactions "*"</code> to a logfile, or sort it directly in the terminal window?</p>
 22: <p>I don't believe bitcoind has any kind of a sort option. The output of <code>bitcoind listtransactions</code> is in chronological order, but the output of your command could be written to a text file and parsed by any number of simple scripts. I don't have one offhand but the output is in JSON which most languages (including <a href="http://docs.python.org/library/json.html" rel="nofollow">Python</a>, my favorite) handle quite nicely. Once you bring the JSON data in it should be a simple matter of <a href="http://wiki.python.org/moin/HowTo/Sorting" rel="nofollow">sorting</a> the transactions array.</p>

<p><strong>Edit:</strong> <em>Depending on what data you're trying to extract and in what format, you may be able to do something with Gavin Andresen's <a href="https://github.com/gavinandresen/bitcointools" rel="nofollow">bitcointools</a> scripts.</em></p>
 5: <p>I am not sure what you mean by sorting, but here is a little python script to check for duplicate txid's:</p>

<pre><code>import json
from sys import argv, stdin

file = stdin.read() #reads transaction list from input
json_file = json.loads(file)

#counts the number of duplicate txid's
txid_list = [transaction["txid"] for transaction in json_file]
print "There are", len(txid_list) - len(set(txid_list)), "duplicates"
</code></pre>

<p>Let's suppose that you save this to a file named <code>check_duplicates.py</code>. Now you just need to output the transactions to a file and feed it to the script:</p>

<pre><code>$ ./bitcoind -datadir=1 listtransactions "*" &gt; transactions.log
$ python check_duplicates.py &lt; transactions.log
There are N duplicates
</code></pre>

<p>Depending on what you need, other sorting operations can be done. It's easy to manage json with python.</p>
 53: <p>You can run the listtransaction JSON output through this little python script (save it as jsonTOCSV.py). That will produce csv (comma separated value) output that Excel or Google Spreadsheets can import, both of which can sort by columns (if I recall correctly).</p>

<p>So:</p>

<blockquote>
  <p>bitcoind listtransactions | jsonTOCSV.py > transactions.csv</p>
</blockquote>

<pre><code>#!/usr/bin/env python
#
# Reads an array of JSON objects and writes out CSV-format,
# with key names in first row.
# Columns will be union of all keys in the objects.
#

import csv
import json
import sys

json_string = sys.stdin.read()
json_array = json.loads(json_string)

columns = set()
for item in json_array:
  columns.update(set(item))

writer = csv.writer(sys.stdout)
writer.writerow(list(columns))
for item in json_array:
  row = []
  for c in columns:
    if c in item: row.append(str(item[c]))
    else: row.append('')
  writer.writerow(row)
</code></pre>
