sqlitetextfixed-width

Import fixed-width text file into sqlite


What is a good way to import fixed-width text files into sqlite tables, preferably without using peripheral software?

E.g. specifying the width of each field

Field 1: 10 characters starting with the second character
Field 2: 5  characters starting with the twelfth character
Field 3: 7  characters starting with the eighteenth character

The line

AABCDEFGHIJABCDEAABCDEFGA

would be imported as:

Field 1     Field 2  Field 3
ABCDEFGHIJ  ABCDE    ABCDEFG

Thanks


Solution

  • The sqlite3 tools imports only CSV files.

    There are third-party tools that can import fixed-width files, but this answer shows how to do this inside SQLite with string functions.