May 30, 2002 #1 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.
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.
May 30, 2002 #2 raider2001 Technical User Apr 27, 2001 488 US Here's one way to put the contents of a file in a variable. set contents=`cat myfile` Upvote 0 Downvote
May 30, 2002 #3 SpongeBob1 Programmer Mar 1, 2002 49 US Hi, I have tried this method, however this does not work, the output is as follows; cat myfile Any other suggestions? Stewart. Upvote 0 Downvote
Hi, I have tried this method, however this does not work, the output is as follows; cat myfile Any other suggestions? Stewart.
May 30, 2002 #4 eholdo Technical User May 30, 2002 31 US 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 Upvote 0 Downvote
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
May 30, 2002 1 #5 tdatgod Programmer Jul 21, 2001 601 US 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 = "`head -$x file | tail -1`" ... operate on $line .... @ x ++ end hope this helps. Upvote 0 Downvote
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 = "`head -$x file | tail -1`" ... operate on $line .... @ x ++ end hope this helps.
May 31, 2002 Thread starter #6 stu78 Programmer May 29, 2002 121 GB Hi All, Thanks to everyone for their help. Stewart. Upvote 0 Downvote