Operating System - HP-UX
1751749 Members
5406 Online
108781 Solutions
New Discussion юеВ

Re: reading and displaying log using csh

 
Henry Chua
Super Advisor

reading and displaying log using csh

Hi Guys,

I used to read lines from a LOGfile using ksh "
#!/usr/bin/ksh
while read line
do
echo "$line"

done < $LOGFILE

but when try using csh, it gives me error "
while: expression syntax".. does this means it doesnt work for csh?.. is there an alternative script I can use to produce the same thing?

regards
Henry
9 REPLIES 9
Biswajit Tripathy
Honored Contributor

Re: reading and displaying log using csh

Shell script syntax can be different from one shell to
another and, as far as I remember, syntax for "while"
loop in csh is different than that in ksh. (I don't think
there is a "do" after "while" in csh). You should
really take a look at csh(1) manpage.

- Biswajit
:-)
Henry Chua
Super Advisor

Re: reading and displaying log using csh

Is there a way to use csh to read line by line of a logfile? possible?
Biswajit Tripathy
Honored Contributor

Re: reading and displaying log using csh

Ofcourse it should be possible, but I can't help you
there (as last time I used csh was atleast 10
years back :-).

But I fail to understand why are you trying to write
this in csh. "ksh" and "sh" are probably the most
popular shells in unix right now and I personally
would not spend any time learning csh. But, ofcourse,
you might have your compelling reason for this. In
that case, someone else in this forum should be
able to help you.

- Biswajit
:-)
Nguyen Anh Tien
Honored Contributor

Re: reading and displaying log using csh

Henry.
I have no time to check correct systax for U.
But you can read shell userguide at
http://docs.hp.com/en/B2355-90046/index.html
HTH
tienna
HP is simple
Bill Hassell
Honored Contributor

Re: reading and displaying log using csh

The similarity between csh and any POSIX shell such as ksh, HP-UX sh, or even bash is about the same as the compatibility between German and French languages. In ksh, the words: while do done are shell keywords and read is a shell built-in. There is no reason to expect csh to recognize these words or process them the same way. The man page for csh explains these in detail.

Now the question: why use a very limited and incompatible shell when your csh users can run the exact same script? The first line (#!/usr/bin/ksh) tells the csh shell to use a different interpreter. This is why a csh, ksh or any other Unix shell user can run a perl script or any other interpreter without changing the current shell. As long as your scripts start with #!/usr/bin.... then you can write your scripts in any shell language that's available on your system.

This link may be helpful: http://www.maths.leeds.ac.uk/~read/csh.html

Note that references to the Bourne shell should be replaced with "POSIX shells including ksh, HP-UX sh, bash, etc)


Bill Hassell, sysadmin
Henry Chua
Super Advisor

Re: reading and displaying log using csh

Hi Guys, thanks for the inputs.. i have gone thru the information u provided.. I am just wondering if u have a sample script for csh to read a log line by line.. I am really new to csh, and for some compelling reason, I am only alow to use C shell script to complete this task.. Apparently there really isnt much info on csh anywhere...

thanks!
Henry
Hein van den Heuvel
Honored Contributor

Re: reading and displaying log using csh

"I am really new to csh, and for some compelling reason, I am only alow to use C shell script to complete this task"

Just say NO! :-).

Yeah I know, easy for me to say, but seriously, for your own sanity please try to get 'them' to articulate why csh is required.

My other 'shoot from the hip' reaction would be: for lexical work like trouncing through a log, use a lexxial tool like AWK or PERL.


>> .. Apparently there really isnt much info on csh anywhere...

For good reason... :-).

Good luck,
Hein.
Henry Chua
Super Advisor

Re: reading and displaying log using csh

Hi Hein ^_^


What can I say..

Well the reason being that I am not able to decipher the following in csh..

"alias CMD1 /usr/bin/cmd1

set planpath = "/users/home1/plan_path"
set tkind = 0x103
alias START 'onintr -; CMD1 path $planpath \!*; CMD1 start \!* $tkind;onintr TEXIT; CMD1 init'

TEXIT:


"
Can it be translated to ksh, if so how??

this is really alien to me..


thanks!!
Henry Chua
Super Advisor

Re: reading and displaying log using csh

example

#!/bin/csh

foreach line (`cat `)
echo $line
end