A User's view of Hledger

Learning about hledger

hledger 1.31 now available, using “not,” awk part 2, podcast of the week

hledger version 1.31 now available

I saw the recent announcement for the release of hledger 1.31, so getting the new version was one of my priorities for this last week. As usual, I turned the task of upgrading to Brew, and it handled the job with aplomb. I have to confess that I hadn’t experienced any problems with the previous version of hledger, but since this is a blog about hledger, I really need to have the latest version installed. That way, anything that I write will reference the latest release.

“Not” to the rescue

The hledger “not” command is one that I don’t use often, but sometimes it’s just what I need. For example, I recently ran the hledger “areg” command to get some information that I was looking for, and I noticed that it worked perfectly except it included one transaction that I didn’t want. Upon further examination, I noticed that the payee for the unwanted transaction was unique. That is, in the output, the only time the payee was listed was in the transaction that I didn’t want. Therefore, I could use “not” to exclude the unwanted transaction. For example, if the transaction in question had Acme in the payee field, I could run my transaction again, adding not:payee:Acme.

If you want to learn more about “not,” please see my introductory video on this topic: hledger: untie your data with “nots.”

Awk, part 2

Last week, I described using a combination of awk and sed to lowercase all the categories in my hledger file. The task for this week was to figure out how to use just awk to do the job. Here is the code for the first part of the solution that I came up with:

{ print "gsub(/" $0 "/, " "\"" tolower($0) "\")" }

I ran the above awk script on my file that contained my hledger account names as follows:

awk -f script accounts.txt > gs

By way of explanation, the “script” file has my one line of awk code listed above. The accounts.txt file has my list of hledger accounts. The output is sent to a new file, gs.

I then hand-edited the gs file to put back in any capitalizations that I wished to keep. For example, if any of my account names were businesses, I kept the name of the business capitalized. For example, I wanted “Acme,” not “acme.”

Also, I had to take care of instances where forward slashes or parentheses were used as part of an account name. In each case, I had to put a backslash in front of each slash or parenthesis. Note, though, that did this only for these two symbols when they were part of an account name. It was important to leave alone the forward slashes and parentheses that awk uses as part of its syntax.

Finally, I had a little more cleaning up to do. In the gs file that got generated, I found a last line that read:

gsub(//, "")

I needed to delete the above line and replace it with the following:

!($0 ~ /:/) { print }

In case you are wondering, the above code passes any lines that have a colon in them unchanged to the output. Why a colon? My hledger file has colons in the lines with the account names, but in no other lines. Therefore, since it’s only the account names that get changed, I can say to output all the other lines just as they were.

Now I am good to have awk run the gs file on a backup of the hledger data file and test to make sure everything works fine, hledger-wise.

Podcast episode of the week

The podcast episode of the week is https://boglecenter.net/bogleheads-on-investing-with-cody-garrett-episode-61/. I found that the following quote was very appropriate for this Thoughtful Thursday blog:

“A lot of times, we’ve been kind of plugging our life into the numbers rather than plugging the numbers into our life. So, we’re starting with the spreadsheet and saying, “how can I live given my spreadsheet” rather than how do I want to live? And how can my spreadsheet support that?”