LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-31-2012, 06:14 PM   #1
eawedat
LQ Newbie
 
Registered: Aug 2012
Posts: 8

Rep: Reputation: Disabled
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.
 
Old 09-01-2012, 02:19 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Quote:
Originally Posted by eawedat View Post
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.
 
2 members found this post helpful.
  


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
echo argument at same line at cshell DoME69 Programming 1 08-04-2011 02:50 AM
Programing Question: Reading file line by line.. then char by char in each line adriumroot Programming 8 05-30-2010 01:55 AM
Error during reading a file line by line in C gozlemci Programming 2 03-06-2010 02:20 AM
File reading line by line and compare Goni Linux - Software 14 09-21-2005 12:24 AM
reading from a file line by line Menestrel Programming 5 12-15-2004 02:17 AM


All times are GMT -5. The time now is 01:49 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