0

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.

Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68

1 Answers1

1

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" } }
raphink
  • 3,625
  • 1
  • 28
  • 39
  • This form is not enough for my purposes. Thank you for your answer! – Adam Ryczkowski Jan 14 '15 at 09:51
  • ...but with little post-processing I might get what I want (e.g. write a script that translates this tree into an INI file, and then use augeas to parse that into the form I want). Can you give me some pointers to some existing lenses that I can adapt to get the format you put? – Adam Ryczkowski Jan 14 '15 at 09:54
  • With little post-processing, you could parse the first line, too, and then correlate the numbers in the first line with the numbers in the other lines, outside of the lens code. – raphink Jan 14 '15 at 15:37