Guides · hledger

hledger CSV import: the rules file, date format and import steps

Updated November 23, 2026 · 8 min read · By the Utilly team

hledger has a CSV converter built in, but it won't guess: every CSV needs a rules file that says which line is the header, which column is the date, how the dates are written and which account the file belongs to. Once that file exists, hledger import brings in only the transactions it hasn't seen before. Here's what goes in a rules file, the import steps, how the overlap check works, PDF statements, Beancount, and free test files with matching rules files and known totals.

Short answer: next to bank.csv, save bank.csv.rules with skip 1, fields date, description, amount, a date-format line if the dates aren't year-first (%m/%d/%Y for 09/01/2026), currency $ and account1 assets:bank:checking. Check it with hledger -f bank.csv print, preview with hledger import bank.csv --dry-run, then run hledger import bank.csv. Free test files: a checking CSV (31 fictional transactions) with its rules file, and a credit card CSV (21) with its rules file.

See the statement behind the test files

Open Utilly's fictional September 2026 checking statement: every line, the balance check from 12,418.36 to 13,440.52, and the CSV and QIF downloads. Free, because the data is made up. The checking test file on this page holds those same 31 lines, so you know exactly what an import should bring in.

Checking CSVChecking rules

1. The test files

These files hold Utilly's fictional September 2026 checking and credit card statements as CSVs, each with a rules file named the way hledger looks for it, so you can try a conversion and an import into a scratch journal and compare the result with known totals. No sign-up.

FileWhat's in itKnown totals
hledger-csv-import-checking.csvA Date, Description, Amount header row, then the 31 lines of the fictional checking statement20 debits 28,575.27; 11 credits 29,597.43; net +1,022.16
hledger-csv-import-checking.csv.rulesIts rules: skip, fields, date-format, currency, account1 assets:bank:checking and 9 if blocks for account29 of the 31 lines stay in expenses:unknown (the 3 checks, 4 debit card purchases, the sales tax payment and the health premium)
hledger-csv-import-credit-card.csvThe same header, then the 21 lines of the matching fictional card statement, by date19 charges 1,939.94; 2 credits 1,542.18; 397.76 more owed
hledger-csv-import-credit-card.csv.rulesIts rules: account1 liabilities:credit card and 7 if blocksEvery line gets an account; the payment goes to assets:transfers

The rows come from Utilly's fictional sample statements (explained on sample bank statement PDF), read by the same engine Utilly's converters use. Each CSV has a date month first (09/01/2026; every file has days past the 12th, so the order can't be misread), the statement description with commas and quote marks taken out, and the amount as one signed number with a period decimal, no thousands separator and no currency symbol. Money out is negative. Keep each CSV and its rules file in the same folder, with the names unchanged.

Date,Description,Amount
09/01/2026,ACH DEBIT GUSTO PAYROLL 0912,-6420.18
09/01/2026,STRIPE TRANSFER ST-K2M8Q4,3184.27
09/02/2026,CHECK 2041,-1850.00

We ran both pairs with hledger 1.52.4 on November 23, 2026: print showed 31 and 21 transactions, import added 52 to an empty journal and found no new transactions on the second run, and hledger check passed.

2. What goes in a CSV rules file

hledger's manual is clear that "Each CSV file must be described by a corresponding rules file." By default hledger looks for it under the CSV's name "with an extra .rules extension added, in the same directory": for bank.csv that's bank.csv.rules. You can point at a different one with --rules. "At minimum, the rules file must identify the date and amount fields", and blank lines and lines starting with # or ; are ignored, so you can comment every rule. Here is the checking test file's rules file in full:

# hledger CSV rules for hledger-csv-import-checking.csv
# Utilly test file: a fictional September 2026 checking statement, 31 transactions.
# Guide: https://getutilly.com/guides/hledger-import-csv
# Save this file next to the CSV, named like the CSV with .rules added.

# the CSV has one header line (Date,Description,Amount)
skip 1

# the three CSV columns, in order, become hledger's date, description and amount
fields date, description, amount

# the dates are month first, like 09/01/2026
date-format %m/%d/%Y

# the amounts have no currency symbol, so add one
currency $

# the account this CSV belongs to
account1 assets:bank:checking

# Unmatched lines go to income:unknown (money in) or expenses:unknown (money out).
# These rules pick a better account by matching text in the line:
if GUSTO PAYROLL
  account2 expenses:payroll

if ADP TAX
  account2 expenses:payroll taxes

if STRIPE TRANSFER|MOBILE DEPOSIT|ZELLE FROM|WIRE TRANSFER IN
  account2 income:sales

if TO SAVINGS
  account2 assets:bank:savings

if AMEX EPAYMENT
  account2 liabilities:amex

if INTUIT|GOOGLE WORKSPACE|ADOBE
  account2 expenses:software

if AUSTIN ENERGY|AT&T
  account2 expenses:utilities

if MONTHLY SERVICE FEE
  account2 expenses:bank fees

if INTEREST PAYMENT
  account2 income:interest
Rulehledger's manual saysWhat it means for you
skipskip N tells hledger "to ignore this many non-empty lines at the start of the input data. You'll need this whenever your CSV data contains header lines."skip 1 for one header row. Banks that put account details above the header need a bigger number; blank lines don't count
fieldsA fields list names the CSV columns in order, and naming one after an hledger field (date, description, amount) assigns itLeave a gap for a column you don't need, as in fields date, description, , amount. Calling a column balance creates balance assertions (section 6)
date-formatNeeded if your CSV dates "are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD". "The pattern must parse the CSV date value completely."%m/%d/%Y for 09/01/2026, %-m/%-d/%Y for 9/1/2026, %m/%d/%y for 09/01/26, %d/%m/%Y for day-first dates
currencyUse it "if the CSV amounts do not have a currency symbol, eg if it is in a separate column."currency $ puts $ in front of every amount, so the journal doesn't mix bare numbers and dollars
account1"Typically account1 is associated with the CSV file, and is set once with a top-level assignment, while account2 is set based on each transaction's description, in conditional rules."One rules file per bank account or card. A card is a liability, so its charges are negative there
if blocksAn if block is "the word if and one or more" matcher expressions, followed by indented rules; a plain matcher is text hledger will "try to match case-insensitively anywhere within the CSV record."Write a word or phrase from the description, or several joined with | as in the test files. When more than one block sets account2, the last one wins
unknown accounts"If a posting's account name is left unset but its amount is set (see below), a default account name will be chosen" (like expenses:unknown or income:unknown)Anything your if blocks miss lands there; hledger bal unknown lists what's left to categorise

hledger also needs clean CSV: it "will only accept valid CSV conforming to RFC 4180". Values may be in double quotes or not, but not single quotes, and there can't be spaces outside the quotes. Name files with a .csv extension (or .ssv/.tsv for semicolons and tabs) so hledger picks the right separator, or add a separator rule.

3. Amounts: one column, two columns and signs

  • One signed column (the test files): map it to amount. That sets the first posting, and "In the second posting, the amount will be negated", so every transaction balances.
  • Debit and Credit columns: use amount-in and amount-out in the fields list. The manual: "hledger assumes both CSV fields contain unsigned numbers, and it automatically negates the amount-out values." In each row only one of the two may hold a non-zero amount. "Don't use both amount and amount-in/amount-out in the same rules file".
  • An amount plus a type column: assume one direction and flip it with an if block, as in the manual's example: amount1 -%Amount then if %Type deposit / amount1 %Amount.
  • Signs in the data: a leading + is dropped, a parenthesised amount like (12.50) becomes -12.50, and two minus signs cancel out.
  • Card files with charges positive: some card CSVs write spending as positive numbers. Name the column amount_ in the fields list and add amount -%amount_: charges then come in negative, and refunds (already negative in such files) come in positive because the two minus signs cancel. The test card file already has charges negative.

4. Importing a CSV, step by step

  1. Put the files together. Save the CSV and its .csv.rules file in one folder, for example your finance folder. Name them so the rules file is the CSV's name plus .rules.
  2. Check the conversion. Run hledger -f hledger-csv-import-checking.csv print. You should see 31 transactions, each with assets:bank:checking and a second account. Fix the rules and run it again until the dates, signs and accounts look right.
  3. Preview the import. Run hledger import hledger-csv-import-checking.csv --dry-run. The import goes to your main journal ($LEDGER_FILE, or the file you give with -f); for a test, use a scratch file: hledger -f test.journal import hledger-csv-import-checking.csv --dry-run.
  4. Import. Drop --dry-run. hledger appends the transactions and reports how many it imported; you can import several files at once, as in hledger import *.csv.
  5. Categorise what's left. Run hledger bal unknown or hledger print unknown, add if blocks for the lines that still say unknown, and use them for the next file.
  6. Reconcile. Compare the account's balance with the statement (section 8).

Since hledger 1.30 you can also name the rules file instead of the CSV, as in hledger import bank.csv.rules, and add a source rule with a pattern such as source Checking1*.csv, so the newest matching download is read straight from your Downloads folder.

5. Overlaps, .latest files and duplicates

Bank downloads overlap, so the import command will "(a) detect the new transactions, and (b) append just those transactions to your main journal." It does this by date, not by matching transactions: it saves the latest date imported from each file in a hidden .latest.FILE file next to it and next time skips the records before that date (and the ones on that date it already took). "It is idempotent, so you don't have to remember how many times you ran it or with which version of the CSV."

  • It works when the file name stays the same between downloads, the dates and the order of same-day lines don't change, and the newest lines have the newest dates. If your bank's file name changes, rename it or use a source pattern.
  • It isn't deduplication. Two identical new lines (two coffees for the same amount on one day) are both imported, as they should be. A new line that matches an entry already in your journal is imported too.
  • First import of data you've already typed in: run hledger import --catchup bank.csv once to mark everything in the file as seen, or create .latest.bank.csv yourself with the last date you already have, written YYYY-MM-DD.
  • Starting over: delete the .latest file and the import will read the whole CSV again.

6. PDF bank statements

hledger converts CSV, SSV and TSV data with rules files; it doesn't read PDFs. Months you only have as PDF statements (older history, a closed account, a bank without downloads) need converting first:

  1. Convert each statement with Utilly's bank statement PDF to CSV converter (card statements: credit card statement to CSV). The free preview shows every line and whether the statement balances before you download.
  2. The clean CSV has Date, Description, Amount and Balance columns, year-first dates (2026-09-01) and a signed Amount with no symbols, so its rules file needs no date-format: skip 1, fields date, description, amount, balance, currency $ and account1 assets:bank:checking.
  3. Naming the fourth column balance turns each running balance into a balance assertion, so hledger checks every line against the bank's balance. That only passes if the journal already holds the opening balance (12,418.36 for the sample, dated before September 1). Without one, the next report stops with a balance assertion error; add the opening balance, or name the column balance_ to ignore it. Card CSVs have an empty Balance column, which adds no assertions.

We ran exactly that on Utilly's own sample CSVs with hledger 1.52.4: with an opening-balance transaction in the journal, all 52 lines imported, hledger check passed and checking ended at 13,440.52, the statement's closing balance. Utilly's checking CSVs are in date order; its card CSV lists the credits first, so sort that one by date if you'll later import overlapping files under the same name.

7. Beancount

Beancount users can use the same CSV and rules files through hledger: import into an hledger journal, then write it out with hledger print -O beancount > september.beancount. hledger renames accounts to Beancount's style (Assets:Bank:Checking) and, because the rules use currency $, writes the amounts in USD. Its manual's advice: "Be cautious and check the conversion until you are confident it is good." For Beancount, "the top level account names must be Assets, Liabilities, Equity, Income, and/or Expenses", which the test rules already use. The Beancount file from our test journal passed bean-check with Beancount 3.2.3.

8. Checking the import against known totals

Import the test files into a scratch journal, then compare:

CheckChecking fileCredit card fileIf it's wrong
Transactions3121None at all: the .latest file says they're already imported; delete it. An error about "Date": skip 1 is missing
Money out28,575.27 (20)1,939.94 (19)Came in positive: the signs are reversed; negate the amount in the rules
Money in29,597.43 (11)1,542.18 (2)Everything on one side: the minus signs were lost, or amount-in/amount-out was used on a signed column
Account balance+1,022.16−397.76A different figure means rows are missing or a sign was flipped. hledger bal assets liabilities shows it
DatesSept 1–30, 2026Sept 1–30, 2026Days and months swapped or an error: the date-format doesn't match the file

The data is fictional (Example Community Bank and Sample Customer LLC don't exist; both statements say SAMPLE STATEMENT, FICTIONAL DATA FOR DEMONSTRATION ONLY). Use a scratch journal for the test, and replace every row and account name before using the rules for real.

9. Import not working: problems and fixes

SymptomLikely cause and fix
could not parse ... as a date using date formatIf the value is Date, the header line wasn't skipped: add skip 1. Otherwise the date-format doesn't describe the whole date value; match it to the file exactly (%m vs %-m for leading zeros, month or day first)
Days and months swappedA day-first date-format on month-first dates (or the reverse) only fails on days past the 12th; earlier dates import swapped. Check a date past the 12th in print
Everything goes to expenses:unknown or income:unknownNo if block matched, or account2 rules are missing. Add matchers for the descriptions; check them with hledger print unknown
no new transactions foundThe .latest file records a date at or after the file's last line. Delete it, or edit the date, to import again
Some new lines were skippedThe file isn't in date order, or its old lines changed. Sort the CSV oldest first and import more often
Balance assertion failedA balance column created assertions but the journal lacks the opening balance, or a line is missing. Add the opening balance, or rename the column balance_
CSV rejected as invalidSingle quotes, spaces outside double quotes, or a stray quote mark inside a field. Clean the file or save it again from a spreadsheet as CSV
Odd amounts after mixing amount and amount-in/amount-outThe manual says not to use both in one rules file. Pick amount for one signed column, amount-in/amount-out for two unsigned columns

Comparing tools? GnuCash maps CSV columns in an import assistant, Firefly III gives each column a role in its Data Importer, and Actual Budget maps a signed Amount column. Need a plain sample file? See sample bank statement CSV.

Get PDF statements into hledger

PDF statements, downloaded or scanned, get a free preview with the balance check, no sign-up. Download a clean CSV with year-first dates, one signed Amount column and a running Balance, ready for a four-line hledger rules file. Files are processed in memory and not stored.

Utilly isn't affiliated with hledger or Beancount. The rules and quotes above are from hledger's own documentation, checked November 23, 2026, and the test files were run with hledger 1.52.4; other versions may differ. Sources: hledger manual (1.52), Tutorial: Import CSV data.

FAQ

Can hledger import a CSV file?

Yes. hledger reads CSV with its built-in converter, guided by a rules file. Put a rules file named like the CSV with .rules added (bank.csv.rules for bank.csv) in the same folder, preview with hledger import bank.csv --dry-run, then run hledger import bank.csv to append the new transactions to your main journal.

What goes in an hledger CSV rules file?

At minimum the date and amount fields. Most rules files also have skip 1 for the header line, a fields list naming the columns (fields date, description, amount), a date-format line when the dates aren't year-first, currency $ when the amounts have no symbol, account1 for the account the CSV belongs to, and if blocks that set account2 from text in the description.

What date-format do I use for MM/DD/YYYY dates in hledger?

date-format %m/%d/%Y. Use %-m/%-d/%Y if the bank leaves out leading zeros (9/1/2026), and %d/%m/%Y for day-first dates. Dates already written YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD need no date-format rule.

Does hledger import skip duplicates?

hledger import skips records it has already seen in that file: it saves the latest imported date in a hidden .latest.FILE file next to the CSV and skips older records next time. The manual says this isn't deduplication. Identical records in new data are imported, so keep the file name and record order stable between downloads.

Can hledger import a PDF bank statement?

No. hledger converts CSV, SSV and TSV files with rules files, not PDFs. Convert the PDF statement to CSV first; a clean CSV with year-first dates and one signed Amount column needs only skip, fields, currency and account1 rules.

Can I use these files with Beancount?

Yes, through hledger. After importing, hledger print -O beancount writes the journal in Beancount's format. Our test journal's Beancount output passed bean-check with Beancount 3.2.3. hledger's manual says to check the conversion until you are confident it is good.

Related tools

  • Bank reconciliation checker: compare a bank statement to your books and list missing, duplicate and mismatched transactions.
  • Receipt to CSV: turn PDF or photo receipts and invoices into CSV, Excel, or QuickBooks and Xero bill imports.