答え1
次の内容で実行可能なスクリプト test.awk を作成します。
awk '
# { system( "echo \"" $0 "\" >&2") }
BEGIN { R = "\"" }
/^###/ {
sub(/\n$/,"",R)
print R "\""
R = "\""
next
}
{
sub(/\n$/,"")
gsub(/"/,"\"\"")
R = R $0 "\n"
}
' $@
その後実行
test.awk longfile.txt > longfile.csv
libreoffice Calcを使用してlongfile.csvを開きます。
長いファイル.txt:
dkdkdkdk
qsdfqlsdf
qsdfjqlsdf
######
qdfqj
qsdfmlkjqsd
qsiapriopazeiru
wqsdfqesr
######
rurururururururuur
rururururururururu
ururururururururur
######
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
######
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
######
長いファイル .csv:
"dkdkdkdk
qsdfqlsdf
qsdfjqlsdf"
"qdfqj
qsdfmlkjqsd
qsiapriopazeiru
wqsdfqesr"
"rurururururururuur
rururururururururu
ururururururururur"
"iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii
iiiiiiiiiiii"
"uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu
uuuuuuuuuuu"