nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Need this script

This is a discussion on Need this script within the Shell scripting forums, part of the Development/Scripting category; Hi guys. I am a linux beginner and I have no idea how to do this so any help would ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 06-12-2006, 05:57 PM
Junior Member
User
 
Join Date: Jun 2006
Posts: 21
Rep Power: 0
karabaja
Default Need this script

Hi guys. I am a linux beginner and I have no idea how to do this so any help would be much appreciated. I need a script that would copy complete content of some files, lets say file1.txt to a html file. But I need it to paste text between <pre> and </pre> in html file. I am not too laisy to do this manually , but this should be done every day so I was hoping to automate the process.

P.S. I know it is not the right place, but if someone knows if this is possible on windows with batch file that would aslo be great.

Thanks in advance.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-12-2006, 07:45 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Do you want a script for UNIX/Linux system or windows system? I can help out about Linux/UNIX script but I have no idea about windows script.. let me know...
Reply With Quote
  #3 (permalink)  
Old 06-12-2006, 08:16 PM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

Use awk
Code:
awk "/<pre>/,/<\/pre>/" file1.txt > out.html
cat out.html
Reply With Quote
  #4 (permalink)  
Old 06-12-2006, 08:56 PM
Junior Member
User
 
Join Date: Jun 2006
Posts: 21
Rep Power: 0
karabaja
Default

Quote:
Originally Posted by monk
Do you want a script for UNIX/Linux system or windows system? I can help out about Linux/UNIX script but I have no idea about windows script.. let me know...
Yes I was asking for linux script. But I don't have linux installed. My friend does, so I was thinking he could run it. I was also considering installing linux along xp. But it would be also good if this could be done on windows in batch file. But I know this is not the place to ask, but if someone could help with that it would be great.

@Tom, thx for that. I'll have to ask my friend to try it out.

And another thing guys, how do I schedule a script to run like at 1:00 AM every day. And since this is only a part of the process I would like to run if you could tell me how do I get it to wait until process is finished before running a next command.
I need this tool to grab some files from the net, then it has command to convert them to txt. Then copy result to template.html file in between pre tags. And ftp html files to server.
So I would need it to wait until grabbing is finished before running a convert command. I think I alreday found a script on this forum that handles uploading files on server. So I would like to know what should be entered in a script after command that grabs the file from net to make it wait before it converts the file. First process takes like 10 minutes, but it varies.
Reply With Quote
  #5 (permalink)  
Old 06-12-2006, 09:31 PM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

You need to use cygwin tool. It is a windows ports of many of the popular GNU software tools, including the BASH, grep, awk and so on.
http://www.cygwin.com/

There are few other ways to install Linux under Windows XP including Free and commercial tools, just have a look at following url
How do I use Linux on windows XP/2000 system? http://www.cyberciti.biz/faqs/2006/0...ows-xp2000.php

If you have remote Linux box, no need to install linux on Windows XP, you can run all scripts on remote linux box:
http://www.cyberciti.biz/faqs/2006/0...-xp-system.php
Quote:
And another thing guys, how do I schedule a script to run like at 1:00 AM every day. And since this is only a part of the process I would like to run if you could tell me how do I get it to wait until process is finished before running a next command.
I need this tool to grab some files from the net, then it has command to convert them to txt. Then copy result to template.html file in between pre tags. And ftp html files to server.
You can use crontab, the tutorial is here http://www.cyberciti.biz/faqs/2006/0...nder-linux.php

To run script called foo.sh 1AM everyday:
Code:
0 1 * * * /path/to/foo.sh
If time varies for second script, then it is better to call it from first script. For example at 1AM foo.sh will grab all files and then call bar.sh:

Code:
#!/bin/sh
# code to grab files
# end 
# call bar.sh to copy and paste stuff
. /path/to/bar.sh
Reply With Quote
  #6 (permalink)  
Old 06-12-2006, 10:18 PM
Junior Member
User
 
Join Date: Jun 2006
Posts: 21
Rep Power: 0
karabaja
Default

Thx for that info, but when I mentioned windows I didn't mean I would like to use this script on windows, I tought it would be good if such operation could be preformed using cmd.exe on xp with commands grouped into a .bat file.
But I guess I could try with cygwin.
Reply With Quote
  #7 (permalink)  
Old 06-12-2006, 11:05 PM
Junior Member
User
 
Join Date: Jun 2006
Posts: 21
Rep Power: 0
karabaja
Default

Quote:
Originally Posted by tom
Use awk
Code:
awk "/<pre>/,/<\/pre>/" file1.txt > out.html
cat out.html
I tried running script.sh using cygwin with these 2 lines and it gave me an empty out.html file. I tried running first line and I got syntax error for awk command. and message "backslash not last character on line"
Reply With Quote
  #8 (permalink)  
Old 06-13-2006, 01:55 PM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

Hmm

It is working here and I'm using Debian Linux.

Code:
cat file1.txt
welcome
This is a test
This is a test
<pre>Code
Some more
code
</pre>
Ok this is a test
done
save
Code:
awk "/<pre>/,/<\/pre>/" file1.txt > out.html
Code:
cat out.html
<pre>Code
Some more
code
</pre>
Reply With Quote
  #9 (permalink)  
Old 06-23-2006, 05:55 AM
Junior Member
 
Join Date: Jun 2006
Posts: 2
Rep Power: 0
Doc_RuNNeR
Default

Maybe that script could answer your problem

$cat > program
echo "<pre>`cat $1`</pre>" > file.html

. program file.txt

Bye
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 05:50 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36