Search code examples
augeas

Is there any hope of parsing csv-like file with augeas?


I am trying to build a lens that would parse a file with the format

#header1 header2 header3

valA1 valA2      valA3
valB1    valB2   valB3

I'd the result to resemble the following tree:

root
 +--[1]
 |   +----header1 -> valA1
 |   +----header2 -> valA2
 |   +----header3 -> valA3
 +--[2]
     +----header1 -> valB1
     +----header2 -> valB2
     +----header3 -> valB3

The problem is that first I need to parse the header line to learn the field names and remember them, and then use them multiple times as the source of key names on all following rows. Does anyone have any idea how to start writing such lens? I've checked all 181 lenses that come bundled with augeas and found no lens that I suspect would parse tables.


Solution

  • No, it's not possible in Augeas to store the values in the header and reuse them as labels for every line.

    You can however build a tree like this one:

    { "#comment" = "header1 header2 header3" }
    { "1"
      { "1" = "valA1" }
      { "2" = "valA2" }
      { "3" = "valA3" }
    { "2"
      { "1" = "valA1" }
      { "2" = "valB2" }
      { "3" = "valB3" } }