LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-19-2002, 02:53 PM   #1
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Rep: Reputation: 32
Post txt file to html > right forum ?


first:

i don`t know if this is the right forum but:


i would like to transfer a txt file order like this:

name familiename departement telefon number mail address

max peterson edv 12345 max.edv@firm.de

into a html file that is showing the people in a beautiful way.

any ideas?
 
Old 03-20-2002, 12:01 AM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
If you are sure that all the fields will be there then the following simple shell script will do. Note that the HTML in this sample is invalid, it's just for example purposes only. Execute somethink like: cat filewithnames | createhtml.sh
Code:
#!/bin/sh

echo "<HTML>"

while [ 1 ]; do
   read ENTRY
   if [ "x$ENTRY" = "x" ]; then
      break;
   fi
   NAME=`echo $ENTRY | awk ' { print $1 } '`
   LAST=`echo $ENTRY | awk ' { print $2 } '`
   DEPT=`echo $ENTRY | awk ' { print $3 } '`
   PHONE=`echo $ENTRY | awk ' { print $4 } '`
   EMAIL=`echo $ENTRY | awk ' { print $5 } '`

   echo "<TAG>Name: $NAME $LAST</TAG>"
   echo "<TAG>Dep: $DEPT</TAG>"
   echo "<TAG>Phone: $PHONE   Email: $EMAIL</TAG>"

done

echo "<HTML>"
 
Old 03-20-2002, 06:00 AM   #3
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
Thumbs up thanks so much

really great thanks for your help.
here some more information.
i will need that script for the intranet in our firm.
i want a someone to care for the txt file and a conjob every x houres to update the html file.
so how would the real file (txt) look?
is it like :

"Tom","Tomason","12345","dep"

or

Thom Tomason 12345 dep

?

and what does "Note that the HTML in this sample is invalid, it's just for example purposes only. " mean?
can`t i just write the script in the vi and make it executable and make a cron every x houres to execute the script?

thank you so much.....
 
Old 03-20-2002, 06:02 AM   #4
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
Lightbulb AH!!!!

oh i just understood !
you meen the tags in the html file will be wrong!
well ok !
thats no problem.
i have some experience in html but not with scripts!
sorry for that..
 
Old 04-16-2002, 08:22 AM   #5
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
Unhappy txt file to html by perl script !

Well hello again!
I have now written the following skript:

-----------------------------------------------------------------
#!/bin/sh

echo "<HTML>"

while [1]; do
read ENTRY
if ["x$ENTRY"="x"];then
break;
fi
Name=`echo $ENTRY | awk '{ print $1}'`
Last=`echo $ENTRY | awk '{ print $2}'`
Dept=`echo $ENTRY | awk '{ print $3}'`
Phone=`echo $ENTRY | awk '{ print $4}'`
Email=`echo $ENTRY | awk '{ print $5}'`

echo "<p> Name: $Name $Last </p>"
echo "<p> Abteilung: $Dept </p>"
echo "<p> Telefon: $Phone </p>"

echo "</HTML>"
-----------------------------------------------------------------

i tried to execute it by typing:

-----------------------------------------------------------------
cat testtelefon | createhtml
-----------------------------------------------------------------

and than the pc sayed:

-----------------------------------------------------------------
<HTML>
/usr/bin/createhtml: line 21: syntax error: unexpected end of file
-----------------------------------------------------------------


1. what does that mean?
2. how can i tell the pc where to generate the file ?

thanx for each idea !

Last edited by saavik; 04-16-2002 at 08:31 AM.
 
Old 04-16-2002, 08:33 AM   #6
hanzerik
Member
 
Registered: Jan 2002
Location: Cheyenne Wyoming
Distribution: Debian/Raspbian/Mint
Posts: 717

Rep: Reputation: 32
I dont know if this helps:
http://linuxcommand.org/writing_shel....html#contents

It shows how to write a script to create a web page using a bash shell script.

here one i did to create a html file to view my firewall logs.

<-----code--------->
#!/bin/bash

# system_page - A script to produce an system information HTML file

##### Constants

TITLE="Firewall Information for $HOSTNAME"
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
DATE_FORMAT=$(date +%f.%y.%T)
##### Functions

function uptime_info
{
echo "<h2>System uptime</h2>"
echo "<pre>"
uptime
echo "</pre>"
}


function firewall_log
{
echo "<h2>Firewall logs</h2>"
echo "<pre>"
cat /var/log/linksys.log
echo "</pre>"
}



##### Main

cat <<- _EOF_ > /html/index.$DATE_FORMAT.html
<html>
<head>
<title>$TITLE</title>
</head>

<body>
<h1>$TITLE</h1>
<p>$TIME_STAMP</p>
$(uptime_info)
$(firewall_log)
</body>
</html>
_EOF_

<-------end code------->

I did this from memory so some things may be different.

Last edited by hanzerik; 04-16-2002 at 08:48 AM.
 
Old 04-16-2002, 09:25 AM   #7
Baloo
Member
 
Registered: Feb 2002
Distribution: LFS
Posts: 41

Rep: Reputation: 15
Do you have a blank line on the end of the script?

Baloo*
 
Old 04-16-2002, 09:42 AM   #8
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
yes i have

is that bad?

well, i will have a trie!
 
  


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
.txt/.rtf/.html eBook reader for Linux? maruchan Linux - Software 3 05-25-2006 07:29 AM
Konqueror + file:/usr/share/doc/HTML/index.html jon_k Linux - Software 2 11-25-2003 06:06 AM
Perl Script Reading a txt file and generate html to be published! kofi Linux - Software 1 09-22-2003 06:12 PM
Convert Powerpoint files to txt,html..... devinWhalen Linux - Software 0 07-29-2003 01:12 PM
How to convert a txt file to be a db file in Redhat linux 9? winnie Linux - Newbie 3 06-27-2003 09:33 AM


All times are GMT -5. The time now is 11:03 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration