LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-17-2015, 06:23 AM   #1
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Rep: Reputation: 15
Smile text line sorting and manipulation


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:

*****************
Click image for larger version

Name:	text.png
Views:	37
Size:	85.8 KB
ID:	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

Last edited by smithy2010; 12-17-2015 at 06:29 AM.
 
Old 12-17-2015, 07:41 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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>|'
 
Old 12-17-2015, 07:44 AM   #3
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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.

Last edited by berndbausch; 12-17-2015 at 07:46 AM.
 
Old 12-17-2015, 08:05 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
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.
 
Old 12-18-2015, 05:36 AM   #5
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Original Poster
Rep: Reputation: 15
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
 
Old 12-18-2015, 07:23 AM   #6
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed append text to end of line if line contains specific text? How can this be done? helptonewbie Linux - Newbie 4 10-23-2013 02:48 PM
Easy string/text manipulation/indentation for restructured text brianmcgee Linux - Software 1 04-22-2008 09:27 PM
text manipulation, REGEX plus the following line farkus888 Solaris / OpenSolaris 3 02-27-2007 07:26 PM
need help with text manipulation pcorajr Programming 12 12-15-2006 08:33 AM
More text manipulation ice_hockey Linux - General 2 05-28-2005 02:43 AM


All times are GMT -5. The time now is 04:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration