The script looks good.  Would it make sense to add assertions for every 
account so closed that the balance is now zero?

Also, for the ledger experts, does the equity report "Opening Balances" 
account adequately replace the prior years' operations?  So for example, if 
you bought an equity last year on April 1 for $100, and just used the 
equity report to open this year's account, would that information be 
preserved if you sold the stock this year?

On Sunday, April 6, 2014 9:18:46 AM UTC-7, Antonio Martinez wrote:
>
> I'm new to ledger and have thought on this same problem. I wrote a dirty 
> shell script to invert the ledger equity report: 
> https://gist.github.com/amarjen/10008046  
>
> #!bin/bash                                                                    
>                                                  
>> # Arguments: $1 --> Ledger source file                                       
>>                                                   
>> #            $2 --> Year Period, eg '2013'                                   
>>                                                   
>> #                                                                            
>>                                                   
>> # Example: bash ledger_close_year.sh mybooks.ledger 2013                     
>>                                                      
>>  
>> # Equity report from ledger
>> ledger -f $1 equity ^Income ^Expenses -p $2 > pl.tmp                         
>>                                                     
>>  
>> # Invert equity report
>> cat pl.tmp | awk 'NR==1 {print '"$2"' "/12/31 Year End Closing Entry"} NR>1 
>> {$1="  "$1; $(NF-1)="  "$(NF-1);$NF=$NF*-1; print}' > closed.tmp             
>>                                                                              
>>                         
>>  
>> # Change the account name
>> sed -i 's/Opening Balances/Retained Earnings/' closed.tmp                    
>>                                                   
>>  
>> # Concatenate output with books in a new file
>> cat $1 closed.tmp > $1.closed                                                
>>                                                   
>>  
>> # Clean temporal files
>> rm pl.tmp closed.tmp    
>>
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to