Re: reading and displaying log using csh (453 Views)
Reply
Super Advisor
Henry Chua
Posts: 444
Registered: ‎09-05-2004
Message 1 of 10 (453 Views)

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
Please use plain text.
Honored Contributor
Biswajit Tripathy
Posts: 508
Registered: ‎12-11-2004
Message 2 of 10 (453 Views)

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
:-)
Please use plain text.
Super Advisor
Henry Chua
Posts: 444
Registered: ‎09-05-2004
Message 3 of 10 (453 Views)

Re: reading and displaying log using csh

Is there a way to use csh to read line by line of a logfile? possible?
Please use plain text.
Honored Contributor
Biswajit Tripathy
Posts: 508
Registered: ‎12-11-2004
Message 4 of 10 (453 Views)

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
:-)
Please use plain text.
Honored Contributor
Nguyen Anh Tien
Posts: 923
Registered: ‎05-20-2004
Message 5 of 10 (453 Views)

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
Please use plain text.
Honored Contributor
Bill Hassell
Posts: 14,205
Registered: ‎05-29-2000
Message 6 of 10 (453 Views)

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)
Please use plain text.
Super Advisor
Henry Chua
Posts: 444
Registered: ‎09-05-2004
Message 7 of 10 (453 Views)

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
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,585
Registered: ‎05-19-2003
Message 8 of 10 (453 Views)

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.
Please use plain text.
Super Advisor
Henry Chua
Posts: 444
Registered: ‎09-05-2004
Message 9 of 10 (453 Views)

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!!
Please use plain text.
Super Advisor
Henry Chua
Posts: 444
Registered: ‎09-05-2004
Message 10 of 10 (453 Views)

Re: reading and displaying log using csh

example

#!/bin/csh

foreach line (`cat `)
echo $line
end
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation