答案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"