Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hmm, so you have lines that have fields in fixed indexed positions? Maybe something line this:

  $ cat hn.txt 
  11alex    a
  12brian   b
  12craig   c
  $ cat test.sql
  .header on
  .mode box
  .load dist/lines0
  select
    substr(line, 1, 2) as id,
    substr(line, 3, 7) as name,
    substr(line, 11, 2) as age
  from lines_read('hn.txt')
  $ sqlite3x :memory: '.read test.sql'
  ┌────┬─────────┬─────┐
  │ id │  name   │ age │
  ├────┼─────────┼─────┤
  │ 11 │ alex    │ a   │
  │ 12 │ brian   │ b   │
  │ 12 │ craig   │ c   │
  └────┴─────────┴─────┘
Unfortunately SQLite's substr function is a bit awkward, but if each field has constant indicies it may work


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: