LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 06-29-2005, 09:54 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
Reading text from a file using shell scripting.


I need to write a shell script that reads text from a file and prints it out. I have never wrote a shell script before and was looking for some help. I have a php3 script that I wrote to do exactly the same thing that I need this shell script to do. Here it is:

Code:
<?php

$filename = "C:\Camera Data\camdata.txt";

$fcontents = file($filename);

foreach($fcontents as $line_num => $line) {
	
	echo "<p><b></b>" . str_replace("<p>", "", $line) ."<br>\n";
}
?>
Can anyone give me some help as to what changes or corrections need to be made to do this?
 
Old 06-29-2005, 10:10 AM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,836

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
i think 'cat' should do what you want (man cat).

basically it would be:

#!/bin/ksh

cat filename


remember to 'chmod 744' your shell script

hope this does it.
~schneidz
 
Old 06-29-2005, 10:12 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Do you need to format the output in HTML like the php script is doing ?
 
Old 06-29-2005, 10:32 AM   #4
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Basically, I have 4 lines of test that get wrote and the written over every second. I just need the text to be printed out four sentences in 4 lines. Will this code do it?:

Code:
#!/bin/ksh

cat filename
I also used this piece of code to refresh the page every second:

Code:
$redirect_page = $HTTP_SERVER_VARS['PHP_SELF'] . "?counter=" . $counter;
?>

<script language="javascript">
setTimeout("window.location = '<? echo $redirect_page; ?>'", 1000);
</script>
Will I be able use this code...or is it not compatible?
 
Old 06-29-2005, 10:40 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Will I be able use this code...or is it not compatible?
not compatible with what ?

Why do you want to write a shell script if you already have a working php solution ?
 
Old 06-29-2005, 10:44 AM   #6
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I have to run the script from a network camera that only supports shell scripting not php. I was checking to see if the java script would be able to be added in a shell script.
 
Old 06-29-2005, 10:46 AM   #7
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Also will cat do what I am trying to do? I need to read a text file and print each line out......is that what cat does?
 
Old 06-29-2005, 11:00 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Okay, a network camera ... is it running linux ?

Well, here is something that may work:

Code:
#!/bin/bash
redirect_page="/xyz";
echo
echo
echo "<pre>"
cat /path/to/filename
echo "</pre>"
cat <<%EOF%
<script language="javascript">
setTimeout("window.location = '$redirect_page'", 1000);
</script>
%EOF%
 
Old 06-29-2005, 11:31 AM   #9
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Yes it has a built in linux os. Could I code this into a text file and upload it to the camera or does it have to be coded in a linux os?
 
Old 06-29-2005, 11:49 AM   #10
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Could this be done as a mish shell instead of a bash shell?

#!/bin/mish

instead of.......

#!/bin/bash
 
Old 06-29-2005, 11:50 AM   #11
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
The linux os is Elinux and the camera supports mish shells
 
Old 06-29-2005, 12:12 PM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
I've no idea what mish shell is, nor want to ...

Well, you can try and see if it works, or find this shell's documentation.
 
  


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
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
reading text from a file mrobertson Programming 16 06-28-2005 12:39 PM
Shell Scripting: using <printf> to align text need HELP!!! naomi Programming 2 01-06-2005 01:06 PM
C++ reading from text file query lrt2003 Programming 5 05-15-2004 04:25 AM
reading a text file and outputting to another. Hardw1re Programming 28 11-03-2003 08:51 AM


All times are GMT -5. The time now is 08:48 PM.

Main Menu
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