Here is a short and sweet awk script some one wrote. You could modify it, for instance if you wanted the ledger in detail rather than the ledger balances.
The output is just the trial balance for the accounts. So in the example output below the newt worth is q/Opening Balances: + i/ accounts + e/ accounts. If you wanted to clear the income and expenses to q/Opening Balances: you could just add the journal entries. Any how you could use the simplicity to develop your own.