LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   cshell reading file line by line (http://www.linuxquestions.org/questions/programming-9/cshell-reading-file-line-by-line-4175425043/)

eawedat 08-31-2012 06:14 PM

cshell reading file line by line
 
hey all,

I have this code :

Code:

#!/bin/tcsh -f

set line=($<)
while($#line > 0)
echo $line[1]
set line=($<)
end

the usage to run the script would be :

Code:

./file < file2
Is there a way to specify filename in the script itself instead of getting/reading file name from STDIN ?


Using :

Code:

set file=data
instead of :

Code:

set line=($<)

thanks.

colucix 09-01-2012 02:19 PM

Quote:

Originally Posted by eawedat (Post 4769522)
Is there a way to specify filename in the script itself instead of getting/reading file name from STDIN?

Nope. The bad new is that the C-shell lacks a real read statement and you can read only from the standard input. The good new is that you can use some trick or better... an external (opposite to shell built-in) command like cat to feed a loop. For example:
Code:

#!/bin/tcsh
foreach line ( "`cat file2`" )
  echo $line
end

You may also take a look at this thread for some other clues about reading and parsing the content of a file. Hope this helps.


All times are GMT -5. The time now is 01:13 AM.