Format text file to html


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format text file to html
# 1  
Old 06-30-2015
Format text file to html

Hi Experts,

Anybody out there figure out on how to achieve in shell scripts or tools. I have done googling to find solutions but no luck.
I have thousands of .txt files to batch process, please see the below sample text content after -------- start here --------. What I want to achieve is to insert html tags to format my content and rename .txt to html.

PS: and heres the tags: <p align="center"> </p> and <p align="justify"> </p>

Thanks

sample snip plain Text File:
http://i58.tinypic.com/2mob3pi.jpg

tags should insert from start and end of paragraph. insert Tags:
http://i59.tinypic.com/2ahcm7s.jpg


and html files should look exactly like this:
http://i58.tinypic.com/o5c038.jpg


Sample inside .txt files

Code:
Republic of the Country



Country Name v. Rodrigo, 19 C.N. 120494 (14875721)


Country Name v. Rodrigo

120494 C.N. 14875721


ON DIVISION OF OPINION OF THE JUDGES

OF THE DISTRICT COURT OF COUTRHR

Uniquerow


0The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near 
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.

Page 120494 C.N. 14875721

1The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.

Page 120494 C.N. 14875722

2The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. 
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. 
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.

Page 120494 C.N. 14875723


This will looks like this:
Code:

<p align="center"> Republic of the Country </p>



<p align="center"> Country Name v. Rodrigo, 19 C.N. 120494 (14875721) </p>


<p align="center"> Country Name v. Rodrigo </p>

<p align="center"> 120494 C.N. 14875721 </p>


<p align="center"> ON DIVISION OF OPINION OF THE JUDGES </p>

<p align="justify"> OF THE DISTRICT COURT OF COUTRHR </p>

<p align="justify"> Uniquerow </p>


<p align="justify"> 0The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near 
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. </p>

<p align="justify"> Page 120494 C.N. 14875721 </p>

<p align="justify"> 1The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river.
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. </p>

<p align="justify"> Page 120494 C.N. 14875722 </p>

<p align="justify"> 2The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. 
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. 
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. </p>

<p align="justify"> Page 120494 C.N. 14875723 </p>


Last edited by lxdorney; 06-30-2015 at 08:58 PM..
# 2  
Old 06-30-2015
What have you done so far? Do you have an example of what your text looks like afterwards? And please wrap your example in code tags. External links are frowned upon unless there solely for extra information.
# 3  
Old 06-30-2015
When to apply "center" and when "justify"?
This User Gave Thanks to RudiC For This Post:
# 4  
Old 06-30-2015
"justify" apply start @ "Uniquerow" from my sample data including the next row before my "Uniquerow" down to each paragraph.

"center" apply to other left paragraph

Code:
<p align="justify"> OF THE DISTRICT COURT OF COUTRHR </p>

<p align="justify"> Uniquerow </p>
.............
.............
<p align="justify"> 2The Quick Brown fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. 
fox jumps over the lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. 
he lazy dog near the bank of the river. The Quick Brown fox jumps over the lazy dog near the bank of the river. </p>

<p align="justify"> Page 120494 C.N. 14875723 </p>

# 5  
Old 07-01-2015
Try
Code:
awk '
/Uniquerow/     {L=1}
                {sub(/^/, "<p align=\"" (L?"justify":"center") "\">")
                 sub (/$/, "</p>")
                 }
1
' RS= ORS="\n\n" file

This User Gave Thanks to RudiC For This Post:
# 6  
Old 07-01-2015
So much thanks you real life saver, BTW when I run the script I notice
Code:
<p align="center"> OF THE DISTRICT COURT OF COUTRHR </p>

instead of
Code:
<p align="justify"> OF THE DISTRICT COURT OF COUTRHR </p>

is their another process run the scripts?
# 7  
Old 07-01-2015
You could replace the /Uniquerow/ match by e.g. a /COUTRHR/ match, but I assume this would not work with the other thousands of files.

It's not that easy to apply a selection / decision to a line before. You could
- use a cyclic buffer but need to modify the to-be-printed element just before printout
- reverse print the file with tac, apply the changes, and reverse with tac again

---------- Post updated at 16:39 ---------- Previous update was at 16:36 ----------

Try
Code:
tac file | awk '
/Unique/        {T=NR+2}
NR == T         {L=1}
                {sub(/^/, "<p align=\"" (L?"center":"justify") "\">")
                 sub (/$/, "</p>")
                }
1
' RS= ORS="\n\n" | tac

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Loop to convert text output in the HTML format

Hello Everyone, I have a sample file raw.txt as shown below : Drive Bays Bay Name : SD-2C Number of Standby Power Supplies : 4 Number of Drive Enclosures : 12 Summary Status of Contained Modules All... (6 Replies)
Discussion started by: rahul2662
6 Replies

2. Shell Programming and Scripting

Convert text file to HTML tabular format.

Please provide script/commands to convert text file to HTML tabular format. No need of styles and colours, just output and a heading in table is required. Output file will be send via email and will be seen from outlook. (script required without using awk). output file content: (sar... (7 Replies)
Discussion started by: Veera_V
7 Replies

3. Shell Programming and Scripting

Read a file and put it in HTML format

Hi, I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail. Communications Pvt Ltd Report AccountId Name Code IdBill Balance ... (3 Replies)
Discussion started by: Kattoor
3 Replies

4. Shell Programming and Scripting

Displaying file in html loses format

I have a bash script to output the contents of a text file to html. Everything outputs ok, except this: ###################################################################### # # # PRIVATE/PROPRIETARY # # # # ANY UNAUTHORIZED ACCESS TO, OR MISUSE OF ABC COMPANY # # SYSTEMS OR DATA MAY... (2 Replies)
Discussion started by: numele
2 Replies

5. Shell Programming and Scripting

how to display the output file in an html format using perl

Hi, I have written a perl script to dispaly some statements from a file but i want the output statements to be dispalyed in an HTML format.Is it possible for me to do in perl scripting? Please help me with ur thoughts. Thanks In Advance Meva. (1 Reply)
Discussion started by: meva
1 Replies

6. Shell Programming and Scripting

Format txt file as html table

I have a short time to solve a problem, so I need some help. I've searched the forum, but I couldn't find a solution to my problem. I made a script to filter some text and now I have a new requirement to make it available as html table. Problem is that I more than one files with different set... (2 Replies)
Discussion started by: tetreb
2 Replies

7. Shell Programming and Scripting

outputting a text file in html

is there anyway i can paste/cat a text file into a html paragraph <p> function html_header { cat <<END <html> <head><title>${1}</title></head> <body> <p> ${2} </p> END } function html_footer { cat <<END </body> </html> END (2 Replies)
Discussion started by: magnia
2 Replies

8. Shell Programming and Scripting

Convert comma text file to Column in html format

I am trying to generate a report with below file : File1 : EQADM,edrtere9-phys,8122caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere11-phys,8227caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere3-phys,822caef0,gpatmon,/bin/ksh,nuten Erick can you help me convert it to html and add... (9 Replies)
Discussion started by: sriram003
9 Replies

9. UNIX for Dummies Questions & Answers

How do I extract text only from html file without HTML tag

I have a html file called myfile. If I simply put "cat myfile.html" in UNIX, it shows all the html tags like <a href=r/26><img src="http://www>. But I want to extract only text part. Same problem happens in "type" command in MS-DOS. I know you can do it by opening it in Internet Explorer,... (4 Replies)
Discussion started by: los111
4 Replies

10. Shell Programming and Scripting

html - text file question

Hi - not sure if this is the correct forum but maybe you can help all the same. I have an ascii file on my server that I log events to.. I have samba and apache running on this server also - although I am not currently using them and have just started them up. They both appear fine so far. I... (5 Replies)
Discussion started by: frustrated1
5 Replies
Login or Register to Ask a Question