# Export to csv problem with multiple entries in tags

**URL:** https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127
**Category:** General Discussion
**Created:** [February 22, 2012, 8:08am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127 "2012-02-22T08:08:29Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 8:08am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/1 "2012-02-22T08:08:29Z")

</div>

Hi,

I am successfully exporting my collection details to csv and can bring it into excel. I use | as a deliminator. (The default ; didn't work because too many titles have that too). Some of my tags have multiple entries, typically genre, and use // as separator for them. The exported file seems to drop anything after // in genre so I only get the first genre item in the csv

Can I do anything fix this?

Thanks Mark

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [February 22, 2012, 8:42am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/2 "2012-02-22T08:42:14Z")

</div>

from the help files:

> [@](#):
>
> **$meta(x)**  
> returns all values of field x (e.g. $meta(artist)). If multiple values of that field exist, they are separated with ", ".
> 
>  
> 
> **$meta(x,n)**  
> returns the nth value of field x (where n starts at 0, e.g. $meta(artist,1)).
> 
>  
> 
> **$meta\_sep(x,sep)**  
> returns all values of field x (e.g. $meta\_sep(artist,; )). If multiple values of that field exist, they are separated with sep.

[https://docs.mp3tag.de/scripting/#metadata-functions](https://docs.mp3tag.de/scripting/#metadata-functions)

---

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 9:01am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/3 "2012-02-22T09:01:46Z")

</div>

> [@pone](#):
>
> from the help files:
> 
> [https://docs.mp3tag.de/scripting/#metadata-functions](https://docs.mp3tag.de/scripting/#metadata-functions)

Hi thanks for that.... looks I need help for the help files!! I have no idea what that all means. It is fun learning though 😃

The more I use mp3tag the more I am impressed with it. You can do just about anything but it takes quite a bit learning for a novice and much testing to figure it out.

Thanks, I think that has pointed me in the right direction

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [February 22, 2012, 9:14am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/4 "2012-02-22T09:14:12Z")

</div>

When you are exporting your tags, you are using an export script.  
Open that script and replace all instances of **%genre%** with **$meta(genre)**  
You have to do this with all tag fields where you have multivalue tags.

---

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 10:03am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/5 "2012-02-22T10:03:08Z")

</div>

Great, that tip helps a lot.

I had found the export scripts and made a simple change. I changed the default delimiter and saved it as a new script but I must admit to being a bit clueless as to how they worked. Is there a help section to explain how the looping part works? I didn't see it in 'scripting' help section?

Mark

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [February 22, 2012, 10:29am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/6 "2012-02-22T10:29:49Z")

</div>

> [@m4rk](#):
>
> Is there a help section to explain how the looping part works? I didn't see it in 'scripting' help section?

yes, in the export help section [https://docs.mp3tag.de/export/#export-scripting-functions](https://docs.mp3tag.de/export/#export-scripting-functions) :

> [@](#):
>
> **$loop(%fieldname%)** starts a new loop. The loop data is sorted by the fieldname.  
> **$loopend()** ends a loop.  
> If you want to limit the loop output to a certain number of entries, simply use $loop(%fieldname%,num). This is useful to eliminate duplicate records (num=1).

So if you have something like

```
$loop(%_filename_ext%)%title%;%artist%;%album%;
 $loopend()

```

the loop writes %title%;%artist%;%album%; + linebreak for every new %\_filename\_ext%.

Whereas this loop

```
$loop(%album%)%albumartist%;%album%;%year%
 $loopend()

```

would write %albumartist%;%album%;%year% + linebreak for every new %album%. So it would skip all files with the same %album% value after writing the values of the first file.

---

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 10:45am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/7 "2012-02-22T10:45:15Z")

</div>

QUOTE (pone @ Feb 22 2012, 12:29) \<{POST\_SNAPBACK}\>

yes, in the export help section [https://docs.mp3tag.de/export/#export-scripting-functions](https://docs.mp3tag.de/export/#export-scripting-functions) :

So if you have something like

```
$loop(%_filename_ext%)%title%;%artist%;%album%;
 $loopend()

```

the loop writes %title%;%artist%;%album%; + linebreak for every new %\_filename\_ext%.

Whereas this loop

```
$loop(%album%)%albumartist%;%album%;%year%
 $loopend()

```

would write %albumartist%;%album%;%year% + linebreak for every new %album%. So it would skip all files with the same %album% value after writing the values of the first file.

Thanks, I now have it working

eg

FLAC tag genre like this:

R&B\\Soundtrack\\Rock

Replaced %genre% with $meta\_sep(genre,\\) in csv export script

now xls import of resultant csv has

R&B\\Soundtrack\\Rock  
in genre column

Perfect 🕶

Thanks again for your help, Mark

---

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 10:51am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/8 "2012-02-22T10:51:50Z")

</div>

QUOTE (pone @ Feb 22 2012, 12:29) \<{POST\_SNAPBACK}\>

yes, in the export help section [https://docs.mp3tag.de/export/#export-scripting-functions](https://docs.mp3tag.de/export/#export-scripting-functions) :

So if you have something like

```
$loop(%_filename_ext%)%title%;%artist%;%album%;
 $loopend()

```

the loop writes %title%;%artist%;%album%; + linebreak for every new %\_filename\_ext%.

Whereas this loop

```
$loop(%album%)%albumartist%;%album%;%year%
 $loopend()

```

would write %albumartist%;%album%;%year% + linebreak for every new %album%. So it would skip all files with the same %album% value after writing the values of the first file.

Again very useful info. I was having to use Excel Office 2007 and the 'remove duplicates' function to create a simple list of albums and their genres.

---

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 11:17am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/9 "2012-02-22T11:17:06Z")

</div>

> [@m4rk](#):
>
> Again very useful info. I was having to use Excel Office 2007 and the 'remove duplicates' function to create a simple list of albums and their genres.

Maybe I am pushing my luck too far today...

$filename(csv,utf-16)|Album|Genre|  
$loop(%album%)|%album%|$meta\_sep(genre,\\)|  
$loopend()

I was hoping this would produce a single line per album but its giving all tracks for the same album!!

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [February 22, 2012, 11:40am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/10 "2012-02-22T11:40:38Z")

</div>

> [@m4rk](#):
>
> Maybe I am pushing my luck too far today...
> 
> $filename(csv,utf-16)|Album|Genre|  
> $loop(%album%)|%album%|$meta\_sep(genre,\\)|  
> $loopend()
> 
> I was hoping this would produce a single line per album but its giving all tracks for the same album!!

Looks like I forgot something in my examples.

$loop(%album%) only sorts your files by %album%  
$loop(%album%,1) sorts your files by %album% and does only write one entrie per %album%.

So try this:

$filename(csv,utf-16)|Album|Genre|  
$loop(%album% **,1** )|%album%|$meta\_sep(genre,\\)|  
$loopend()

---

<div class="post-metadata">

### Author: ![m4rk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@m4rk](https://community.mp3tag.de/u/m4rk)
#### Post date: [February 22, 2012, 11:54am UTC](https://community.mp3tag.de/t/export-to-csv-problem-with-multiple-entries-in-tags/13127/11 "2012-02-22T11:54:19Z")

</div>

> [@pone](#):
>
> Looks like I forgot something in my examples.
> 
> $loop(%album%) only sorts your files by %album%  
> $loop(%album%,1) sorts your files by %album% and does only write one entrie per %album%.
> 
> So try this:
> 
> $filename(csv,utf-16)|Album|Genre|  
> $loop(%album% **,1** )|%album%|$meta\_sep(genre,\\)|  
> $loopend()

yup, that was it. I learnt a lot quickly today thanks to your suggestions. Thanks, much appreciated 🕶
