# Customize account2 of CSV rules depending on the file parsed

**URL:** <https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762>\
**Category:** General\
**Tags:** hledger\
**Created:** [March 10, 2026, 6:08pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762 "2026-03-10T18:08:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zako](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/zako/32/21_2.png) [@zako](https://forum.plaintextaccounting.org/u/zako)\
**Post date:** [March 10, 2026, 6:08pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/1 "2026-03-10T18:08:24Z")

</div>

Hello,

I have a `expenses.csv.rules` file which is included by the rules files of different bank accounts: `personal-bank.csv.rules` and `family-bank.csv.rules`. Bank rule files parse the CSV fields and set the account1 whereas the common expenses csv file sets the description and account2 (the category of expense). The description and category of the expenses are the same for my personal and familiar books.

One example of one entry of my `expenses.csv.rules`:

```auto
if carrefour
    description carrefour | some explanation
    account2 expenses:supermarket

```

What I would like to get is to set account2 to`expenses:family:supermarket` if the `expenses.csv.rules` file was included by the `family-bank.csv.rules` file and to set `expenses:personal:supermarket` if the `expenses.csv.rules`was included by `personal-bank.csv.rules`.

Is that possible?

---

<div class="post-metadata">

**Author:** ![simonmic](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/simonmic/32/1_2.png) [@simonmic](https://forum.plaintextaccounting.org/u/simonmic)\
**Post date:** [March 10, 2026, 6:49pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/2 "2026-03-10T18:49:32Z")

</div>

The rules can't detect which files are including them; but you can just add overriding rules in each including file, after the `include`.

---

<div class="post-metadata">

**Author:** ![zako](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/zako/32/21_2.png) [@zako](https://forum.plaintextaccounting.org/u/zako)\
**Post date:** [March 11, 2026, 9:10pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/3 "2026-03-11T21:10:40Z")

</div>

Do you mean overriding rules after the include such as:

```auto
include categorization.rules
if %account2 expenses:(.*)
    account2 expenses:family:\1

```

I tried this, but it does nothing. I think the issue is that [field matchers should only be CVS field names or numbers](https://hledger.org/1.51/hledger.html#matchers) and account2 is not a CSV field name.

---

<div class="post-metadata">

**Author:** ![simonmic](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/simonmic/32/1_2.png) [@simonmic](https://forum.plaintextaccounting.org/u/simonmic)\
**Post date:** [March 12, 2026, 3:51am UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/4 "2026-03-12T03:51:54Z")

</div>

Yes that's what I meant, and yes you're right. hledger fields can only be written to, not read.  
[CSV fields and hledger fields](https://hledger.org/1.51/hledger.html#csv-fields-and-hledger-fields)

---

<div class="post-metadata">

**Author:** ![Xavier](https://avatars.discourse-cdn.com/v4/letter/x/2bfe46/32.png) [@Xavier](https://forum.plaintextaccounting.org/u/Xavier)\
**Post date:** [March 12, 2026, 4:05am UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/5 "2026-03-12T04:05:38Z")

</div>

Can we have a rule for a specific day ?

Say for example that if I spent money at a place, I’d like it to be expense:place but if it was on the 1st of january, I’d like it to be expense:party.

Possible ?

---

<div class="post-metadata">

**Author:** ![simonmic](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/simonmic/32/1_2.png) [@simonmic](https://forum.plaintextaccounting.org/u/simonmic)\
**Post date:** [March 12, 2026, 7:01am UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/6 "2026-03-12T07:01:55Z")

</div>

Sure. Assuming ISO date format,

```
if %date -01-01
 ...

if ! %date -01-01
 ...

```

---

<div class="post-metadata">

**Author:** ![Xavier](https://avatars.discourse-cdn.com/v4/letter/x/2bfe46/32.png) [@Xavier](https://forum.plaintextaccounting.org/u/Xavier)\
**Post date:** [March 12, 2026, 10:44am UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/7 "2026-03-12T10:44:14Z")

</div>

and can have multiple if-conditions ?

---

<div class="post-metadata">

**Author:** ![simonmic](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/simonmic/32/1_2.png) [@simonmic](https://forum.plaintextaccounting.org/u/simonmic)\
**Post date:** [March 12, 2026, 4:10pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/8 "2026-03-12T16:10:18Z")

</div>

Yes, you can see the syntax here:  
[https://hledger.org/hledger.html#if-block](https://hledger.org/hledger.html#if-block)

---

<div class="post-metadata">

**Author:** ![Xavier](https://avatars.discourse-cdn.com/v4/letter/x/2bfe46/32.png) [@Xavier](https://forum.plaintextaccounting.org/u/Xavier)\
**Post date:** [March 12, 2026, 8:05pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/9 "2026-03-12T20:05:15Z")

</div>

Wow perfect !

---

<div class="post-metadata">

**Author:** ![Xavier](https://avatars.discourse-cdn.com/v4/letter/x/2bfe46/32.png) [@Xavier](https://forum.plaintextaccounting.org/u/Xavier)\
**Post date:** [March 13, 2026, 10:05am UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/10 "2026-03-13T10:05:38Z")

</div>

Another question.

What is the correct syntax for a OR in a if-table ?

---

<div class="post-metadata">

**Author:** ![simonmic](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/simonmic/32/1_2.png) [@simonmic](https://forum.plaintextaccounting.org/u/simonmic)\
**Post date:** [March 13, 2026, 6:23pm UTC](https://forum.plaintextaccounting.org/t/customize-account2-of-csv-rules-depending-on-the-file-parsed/762/11 "2026-03-13T18:23:35Z")

</div>

Hi @Xavier, it's described in that link above - put each pattern on its own line. Or you can use `|` on the same line, if you know regular expressions. But we are off topic from @zako's original post, so make a new post if you'd like to discuss more, or better still, come to the [chat room](https://hledger.org/support).
