Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. TSV out of a tab-based tree-like file

TSV out of a tab-based tree-like file

Scheduled Pinned Locked Moved Regular Expressions
javajavascriptdatabasecomdata-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DynV
    wrote on last edited by
    #1

    From a tab-based tree-like file, I'd like to get a flat-file DB (I think I'll make a program out of it and probably using ECMAScript/JavaScript, but whatever I end up doing I need a DB to start with). The file have different 1st-level block items, that is starting right after \n and ending just before either "\n\w" or EOF (end of file); I'm only interested in a certain kind: starting with "\nsystem\s", which I'll refer to as "system". A good portion of systems have a 2nd-level (non-block) item, that is starting right after \n\t and ending just before either "\n" or EOF (end of file); I'm only interested in those starting with "\n\tlink\s", which I'll refer to as "link"; any of those cases have > 1 link. I'm thinking the links can be in a CSV. All systems have a single 2nd-level "pos", which has 2 digits, that can be negative. To summarize: Not all 1st-level items are systems but I'm only interested those. Some systems have no link, a decent portion have just 1, and a large portion have > 1, whichever of those cases I need links to be listed. A good portion of names, be it system or link are double-quoted which I don't want (the quotes). The input file is https://github.com/endless-sky/endless-sky/blob/master/data/map.txt and the following is its current version 1st 2 systems trailed by an example of a system without a link and after is the output I'm looking to have from that. I'd prefer to run the regex in Notepad++, but worse case I have Cygwin so I could use some *nix tools although please note often Cygwin version is old (so if someone want me to use the latest *nix tool, there's a decent chance I won't be able to in Cygwin). Thank you kindly for your help Sample input ```text # Copyright (c) 2014 by Cookie Monster system "1 Axis" pos -1274.63 267.214 government Coalition habitable 745.92 belt 1112 link "Sol Kimek" link "4 Winter Rising" link "4 Spring Rising" link "3 Axis" asteroids "small rock" 8 3.3166 asteroids "medium rock" 11 3.4454 asteroids "large rock" 1 3.1556 asteroids "small metal" 1 3.381 asteroids "medium metal" 149 4.347 asteroids "large metal" 11 3.9606 minables lead 11 6.87213 minables silicon 35 6.68659 minables tungsten 2 5.45307 trade Clothing 251 trade Electronics 831 trade Equipment 469 trade Food 231 trade "Heavy Metals" 1241 trade Industrial 767 trade "Luxury Goods" 1135 trade Medical 777 trade Metal 520 trade Plastic 384 fleet "Small Arach" 700 fleet "Large Arach" 1500 fleet "Small Kimek" 300 fleet "Large

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups