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
The link in the answer above is for generic SQL. Here is one way to do it in SQLite:
CREATE TABLE fixed_width_table (full_string CHAR);
.import fixed_width_file.txt fixed_width_table
CREATE TABLE tmp AS
Select
SUBSTR(full_string,1,11) AS field1
,SUBSTR(full_string,2,5) AS field2
,SUBSTR(full_string,2,7) AS field3
FROM fixed_width_table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With