LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Reading text from a file using shell scripting. (https://www.linuxquestions.org/questions/programming-9/reading-text-from-a-file-using-shell-scripting-338388/)

mrobertson 06-29-2005 09:54 AM

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?

schneidz 06-29-2005 10:10 AM

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

jlliagre 06-29-2005 10:12 AM

Do you need to format the output in HTML like the php script is doing ?

mrobertson 06-29-2005 10:32 AM

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?

jlliagre 06-29-2005 10:40 AM

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 ?

mrobertson 06-29-2005 10:44 AM

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.

mrobertson 06-29-2005 10:46 AM

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?

jlliagre 06-29-2005 11:00 AM

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%


mrobertson 06-29-2005 11:31 AM

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?

mrobertson 06-29-2005 11:49 AM

Could this be done as a mish shell instead of a bash shell?

#!/bin/mish

instead of.......

#!/bin/bash

mrobertson 06-29-2005 11:50 AM

The linux os is Elinux and the camera supports mish shells

jlliagre 06-29-2005 12:12 PM

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.


All times are GMT -5. The time now is 04:18 AM.