文字で区切られたデータがあり\002
ます。これは私がそれをインポートするために使用するものです:
cat data.txt \
| tr -d '\r' \
| tr '\n' '\003' \
| tr '\t' ' ' \
| tr '\001' '\t' \
| tr '\002' '\n' \
| sed 's%\003%\\n%g' \
> data-formatted.txt
このコマンドは\r
、文字を消去し、 に変更\n
し\\n
、改行に変更し\002
ます\n
前のフォーマット:
http://wikisend.com/download/486524/data.txt
Not Escaped:
1 new
line 2 new
line
2
Escaped:
1\001new\nline\002\001
2\001new\nline\n2\002\001
後のフォーマット:
Not Escaped:
1 new\\nline
2 new\\nline\\n2
Escaped:
1\tnew\\nline\t\n
2\tnew\\nline\\n2\t\n
問題は、データが\n
改行ではなくインポートされていることです。
これが私のインポートスクリプトです:
import.txt:
.separator "\t"
.import data-formatted.txt my_table
そして私のインポートコマンド:
cat import.txt | sqlite3 my.db
データをテストするには:
echo 'SELECT * FROM my_table;' | sqlite3 my.db
1|new\nline|
2|new\nline\n2|
データ フィールドに \n を改行としてインポートするにはどうすればよいですか?