Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cshell read file 1

Status
Not open for further replies.

stu78

Programmer
May 29, 2002
121
GB
Hi all,

I wish to read in a file ( txt will do ) in a c shell script. Is this possible? Anyone have any ideas how to do this?

Thanks.
Stewart.
 
Here's one way to put the contents of a file in a variable.

set contents=`cat myfile`
 
Hi,

I have tried this method, however this does not work, the output is as follows;


cat
myfile

Any other suggestions?
Stewart.
 
I think you missed the ` surrounding cat myfile. This will execute the command between the ` character. The ` is usually to the left of the 1 key.

If the file is too long, you may be out of luck. I usually create a temp file such as
cat - > file1

This takes standard input and redirects to a temporary file. Then run your script on the file.

Hope this helps
 
Hi,
with PERL you can read the whole file into a variable.

CSH doesn't allow unlimited number of words to be assigned to a variable.

Most typically you operate on the whole file at a time putting the results in another file.

Unlike sh which has a nice READ command to get the next line of a file, CSH doesn't have a way to get the next line of a file.

The best you can do is simulate the read command.

@ x = 1
set a = `cat file | wc -l`
while ( $x <= $a )
set line = &quot;`head -$x file | tail -1`&quot;
... operate on $line ....
@ x ++
end


hope this helps.



 
Hi All,

Thanks to everyone for their help.

Stewart.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top