Awk set data parser

All add-on programm and tools for wagic
Locked
neurignacio
Posts: 1
Joined: Wed Dec 31, 2014 12:14 pm

Awk set data parser

Post by neurignacio »

A simple parser for the set data file (_cards.dat) using awk:

Code: Select all

awk -F'=' '/primitive/ {n=$2} /id/ {i=$2} /rarity/ {r=$2} {if (/rarity/) {printf ("%s\t%s\t%s\n",substr(n,1,length(n)-1),substr(i,1,length(i)-1),substr(r,1,length(r)-1))}}' _cards.dat
It extracts the primitive, id, and rarity fields and prints them out in a column tabbed format. The last '\n' character has to be left for correct formatting.

It also works together with 'find' for parsing multiple sets.

Code: Select all

find . -name "_cards.dat" | xargs awk -F'=' '/block/ {n=$2} /primitive/ {p=$2} /id/ {i=$2} /rarity/ {r=$2} {if (/rarity/) {printf ("%s\t%s\t%s\t%s\n",substr(n,1,length(n)-1),substr(p,1,length(p)-1),substr(i,1,length(i)-1),substr(r,1,length(r)-1))}}' > setcards.csv
Here, it extracts the previous fields as well as the block field and save it in a csv file
driverstadium
Posts: 1
Joined: Thu Nov 10, 2022 7:55 am

Re: Awk set data parser

Post by driverstadium »

The primitive, id, and rarity fields are extracted, and they are printed in a column-tabbed fashion. For proper formatting, the final 'n' character must be retained in place. Additionally, it works well with "find" when processing several sets.

super mario bros
Locked