LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   text line sorting and manipulation (https://www.linuxquestions.org/questions/linux-newbie-8/text-line-sorting-and-manipulation-4175561662/)

smithy2010 12-17-2015 05:23 AM

text line sorting and manipulation
 
1 Attachment(s)
Hi all,

i need some help please:

I have a text document with over 65000 lines of text, which i want to convert into a web page...the problem i find is how the text is aligned at the moment:

Text file example 1:

*****************
Attachment 20314


************

so when I run this command: sed -i '10,66748 s/.*/<p>&<p>/' filename it adds start and end of the line so it is displayed in firefox in order as shown here:

Example 2:
***********
Chapter 1 12 And the earth brought forth the green
herb, and such as yieldeth seed according to its
In the beginning God created heaven, and earth. kind, and the tree that beareth fruit, having seed
2 And the earth was void and empty, and each one according to its kind. And God saw
darkness was upon the face of the deep; and the that it was good.
spirit of God moved over the waters. 13 And the evening and the morning were the
3 And God said: Be light made. And light third day.
was made. 14 And God said: Let there be lights made
4 And God saw the light that it was good; and in the firmament of heaven, to divide the day
he divided the light from the darkness. and the night, and let them be for signs, and for
5 And he called the light Day, and the dark- seasons, and for days and years:
*********************

but reading doesn’t make sense as it is all jumbled up...so my question is:

do you know a command or a way to sort the text out so it can be displayed in web browser as shown in example 1.

Thank you in advance

Denis

berndbausch 12-17-2015 06:41 AM

If by "jumbled up" you mean that paragraph 13 follows 2 etc, this is not the fault of the sed command. There must be something else.

By the way, your HTML is probably not correct. I would say
Code:

sed 's|.*|<p>&</p>|'

berndbausch 12-17-2015 06:44 AM

Oh I understand now. You have two column text. Does the web page have to be in two columns as well?

You can turn the source text into one column text with two cut commands, one per column, and combine the two results with cat.

pan64 12-17-2015 07:05 AM

in that case you ought to try awk/perl/python, they can split by column too and construct html pages, although I would rather look for better source if possible.

smithy2010 12-18-2015 04:36 AM

Hi all,

thank you for your reply...and yes I would like the web page to be in two columns as well if possible, however if not possible then perhaps to convert source text from two columns into one ...the rest I know how to do it..

I also run the command suggested by berndbausch but unfortunately that did not produce the results I wanted.

in case anyone is up for a challenge, please let me know and I’ll upload text file I am referring to.

Cheers

Denis

berndbausch 12-18-2015 06:23 AM

You can use an HTML table to provide two-column output, or perhaps newer HTML and/or CSS has special tags for that.

As I said, using the cut command you can extract columns from the text file, then put them in the appropriate HTML or CSS code. The screenshot seems to indicate, though, that the source text contains lines that straddle the columns, which complicates things.

To clarify: Assume a file like this -
Code:

column1 line 1    column 2 line 1
column1 line 2    column 2 line 2

where column 2 always starts at character position 20. Use cut to create two separate files like this:
Code:

cut -c1-19 inputfile > col1file
cut -c20- inputfile > col2file

then format col1file and col2file with your html and css code. Which I won't be able to help with.


All times are GMT -5. The time now is 01:33 PM.