Displaying file in html loses format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Displaying file in html loses format
# 1  
Old 03-07-2010
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:
Code:
######################################################################
 # #
 # PRIVATE/PROPRIETARY #
 # #
 # ANY UNAUTHORIZED ACCESS TO, OR MISUSE OF ABC COMPANY #
 # SYSTEMS OR DATA MAY RESULT IN CIVIL AND/OR CRIMINAL #
 # PROSECUTION, EMPLOYEE DISCIPLINE UP TO AND INCLUDING #
 # DISCHARGE, OR THE TERMINATION OF VENDOR/SERVICE CONTRACTS. #
 # #
 # ABC COMPANY MAY PERIODICALLY MONITOR AND/OR AUDIT SYSTEM #
 # ACCESS/USAGE. #
 # #
 # #
 ######################################################################

Should look like this:
Code:
######################################################################
#                                                                    #
#                    ***PRIVATE/PROPRIETARY***                       #
#                                                                    #
#       ANY UNAUTHORIZED ACCESS TO, OR MISUSE OF ABC COMPANY         #
#       SYSTEMS OR DATA MAY RESULT IN CIVIL AND/OR CRIMINAL          #
#       PROSECUTION, EMPLOYEE DISCIPLINE UP TO AND INCLUDING         #
#       DISCHARGE, OR THE TERMINATION OF VENDOR/SERVICE CONTRACTS.   #
#                                                                    #
#       ABC COMPANY MAY PERIODICALLY MONITOR AND/OR AUDIT SYSTEM     #
#       ACCESS/USAGE.                                                #
#                                                                    #
#                                                                    #
######################################################################

The part of my script that uses this:
Code:
#!/bin/bash
echo "Content-type: text/html"
echo ""
TEXT=`echo "$QUERY_STRING" | sed -n 's/^.*var=\([^&]*\).*$/\1/p'`
FILE=$(cat /usr/local/apache/$TEXT | nawk 'sub("$","<br>")' |\
 sed -e "s/\*\*\*/ /g" -e "s/\*\*/ /g")
echo $FILE

I had to remove the combinations of ** and *** because for some reason where ever they were in the file, the output would display all of the directory files. If I took the *'s out, it would not do this.
# 2  
Old 03-07-2010
Hi, numele:

Multiple instances of whitespace in html are rendered as one space. If you need to preserve formating, look into using the <pre> element or perhaps substituting &nbsp; (non-breaking space html entity) for each space in the text.

The expansion of * into the list of files in the current working directory (pathname expansion aka globbing) is ocurring because you have not double-quoted "$FILE" in the final statement. This happens because pathname expansion occurs after parameter expansion (the substitution of $FILE with the text it stores). Double quoting prevent the pathname expansion from happening.

Regards,
Alister

Last edited by alister; 03-07-2010 at 02:13 PM..
# 3  
Old 03-07-2010
Thank you Alister, after I quoted my echo "$FILE" and used <pre> everything displays correctly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (10 Replies)
Discussion started by: lxdorney
10 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

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

4. Shell Programming and Scripting

Displaying output in the tabular format

Hi I want to display the following input data into the tabular format as shown in the output. Input.txt: Following jobs are in pending state for more than 10 minutes: JOB_ID JOB_SUBMIT_ID MAHAR 784308 PUNJA 109367 Following jobs are running for longer time: JOB_ID... (1 Reply)
Discussion started by: dats
1 Replies

5. 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

6. 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

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

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

copy loses the text format

Hi I try to copy part of text from one file to another file. My problem is the text in the new file loses all the format. My code is: #!/bin/sh while red line do if then echo "$line" >> ./new_file else break fi done < "./old_file" Is there a way to modify... (3 Replies)
Discussion started by: tiger99
3 Replies

10. UNIX for Dummies Questions & Answers

displaying directory in html

How would i in a csh script get it to display all the files in the current directory in html? (9 Replies)
Discussion started by: adel66
9 Replies
Login or Register to Ask a Question