I am trying to write a script to reformat some text.
pages: page1: gui-rows: 6 items: '6': material: CAT_SPAWN_EGG buy: 999999999 sell: -1 '7': material: CAVE_SPIDER_SPAWN_EGG buy: 999999999 sell: -1 page2: gui-rows: 6 '8': material: CHICKEN_SPAWN_EGG buy: 999999999 sell: -1
The expected output would be
'6': type: item item: material: CAT_SPAWN_EGG buyPrice: 999999999 sellPrice: -1 slot: 6 '7': type: item item: material: CAVE_SPIDER_SPAWN_EGG buyPrice: 999999999 sellPrice: -1 slot: 7 '8': type: item item: material: CHICKEN_SPAWN_EGG buyPrice: 999999999 sellPrice: -1 slot: 8
Using this cat 0.yml | sed "/page.*/d" | sed "/gui-row.*/d" | sed "/item.*/d" | sed "s/ / /g" | sed "s/.*':/&\\n type: item\\n item:/g" | sed "s/material.*/ &/g" |sed "s/buy/buyPrice/g" | sed "s/sell/sellPrice/g" | sed "s/sell.*/&\n slot: X"
I get this:
'6': type: item item: material: CAT_SPAWN_EGG buyPrice: 999999999 sellPrice: -1 slot: X '7': type: item item: material: CAVE_SPIDER_SPAWN_EGG buyPrice: 999999999 sellPrice: -1 slot: X '8': type: item item: material: CHICKEN_SPAWN_EGG buyPrice: 999999999 sellPrice: -1 slot: X
yq -Y '.pages[] | .items | with_entries(.value |= {"type": "item", "item": {material}, "buyPrice": .buy, "sellPrice": .sell} | .value += {"slot": .key | tonumber})' file.yml
sed: -e expression #1, char 25: unterminated
s' command`