Moving half sentence from field to field by batch editing

I’m Brazilian, trying learn English. Well, at the moment, I have 5281 cards in my Anki kind of:

- Front: phrase + audio clip
- Back: translation

For example:
Front: He went to jail.[sound:google-f703bc44-948463ed-0bf1939d-19097d5a-c81e95f4.mp3])
Back: Ele foi para a prisão (translation).

Now, I would like to train my listening. So I would need keep only the audio code in Front and move the phrase from Front to Extra, like:

Front: [sound:google-f703bc44-948463ed-0bf1939d-19097d5a-c81e95f4.mp3]
Back: Ele foi para a prisão (translation)
Extra: He went to jail.

All this in ever card (5281).

Does anyone know how I may do it?

Thank so much.

Try the following code in the debug console after changing Basic in the first line to the name of the notetype of the cards:

NOTETYPE_NAME = "Basic"
nids = mw.col.find_notes(f'note:"{NOTETYPE_NAME}"')
notes = []
RE = re.compile(r"(.*)(\[sound:.*\])")
for nid in nids:
    note = mw.col.get_note(nid)
    m = RE.match(note['Front'])
    if m:
		if m.group(2):
            note['Front'] = m.group(2)
        if m.group(1):
		    note['Extra'] = m.group(1)
        notes.append(note)

mw.col.update_notes(notes)

Please take a backup of your collection before running the code. See Exporting - Anki Manual

4 Likes

One other approach is documented here: Splitting a field into multiple fields - Frequently Asked Questions

2 Likes

Thanks, Abdo!!

I tried but got an error:

NOTETYPE_NAME = “BasicTestes”
… nids = mw.col.find_notes(f’note:“{NOTETYPE_NAME}”')
… notes =
… RE = re.compile(r"(.)([sound:.])")
… for nid in nids:
… note = mw.col.get_note(nid)
… m = RE.match(note[‘Front’])
… if m:
… if m.group(2):
… note[‘Front’] = m.group(2)
… if m.group(1):
… note[‘Extra’] = m.group(1)
… notes.append(note)
… mw.col.update_notes(notes)
Traceback (most recent call last):
File “aqt\main.py”, line 1473, in onDebugRet
File “”, line 6, in
AttributeError: ‘Collection’ object has no attribute ‘get_note’

Would you know how to fix it?

Updateing

On searching about that error, I found that “get_note” could be changed to “getNote”. Apparently, it worked. But a new erro has happened:

AttributeError: ‘Collection’ object has no attribute 'updated_notes’

I couldn’t find some code that may replace ‘updated_notes’

update_notes should work in the latest version. Try the following code instead:

NOTETYPE_NAME = "Basic"
nids = mw.col.find_notes(f'note:"{NOTETYPE_NAME}"')
RE = re.compile(r"(.*)(\[sound:.*\])")
for nid in nids:
    note = mw.col.getNote(nid)
    m = RE.match(note['Front'])
    if m:
		if m.group(2):
            note['Front'] = m.group(2)
        if m.group(1):
		    note['Extra'] = m.group(1)
	    mw.col.update_note(note)
1 Like

Thanks for trying help, friend! Unfortunately, it didn’t work:

By the way, my anki is 2.1.40

Replacing mw.col.update_note(note) with note.flush() should work on your Anki (and I guess is more appropriate here since update_note will add an undo entry for each note, slowing things down).

1 Like

It works!! Thank so much!!