-1

I have a large file that's a couple hundred lines long. This file is partitioned into many parts by a specific separator,'###'. This line '###' appears after a couple of lines which may vary each time.So I need the content before '###' to be in one cell of a single excel file and contents after '###' to be in separate cell of same excel file.enter image description here I'm familiar with split and awk but can't seem to create a command line that will do what I've described, any ideas?

closed as unclear what you're asking by Michael Homer, Thushi, Thomas, schily, Jeff Schaller Jun 7 '18 at 10:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • How do you make this Excel file, and how do you then read it? – Michael Homer Jun 7 '18 at 7:18
  • @MichaelHomer - I redirect the output of text file to a .xls file . There is where I need this formatting to be done. – user3851659 Jun 7 '18 at 7:22
  • That is not how xls files work, nor xlsx files. Are you saying you've made a text file and called it something.xls? – Michael Homer Jun 7 '18 at 7:25
  • @MichaelHomer yes exactly – user3851659 Jun 7 '18 at 7:29
2

Create an executable script, test.awk, with following contents:

awk '
  # { system( "echo \"" $0 "\" >&2") }
  BEGIN { R = "\"" }
  /^###/ {
    sub(/\n$/,"",R)
    print R "\""
    R = "\""
    next
  }
  {
    sub(/\n$/,"")
    gsub(/"/,"\"\"")
    R = R $0 "\n"
  }
' $@

then run

test.awk  longfile.txt  > longfile.csv

Open longfile.csv with libreoffice Calc.

longfile.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
######

longfile.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"

Not the answer you're looking for? Browse other questions tagged or ask your own question.