---------------------------------------------------- Exercise #2 for DAT2330 - Ian Allen - idallen@ncf.ca ---------------------------------------------------- Global weight: 1% of your total mark this term Due date: 12h00 (noon) Friday, January 24. Cutoff date: I will accept without penalty exercises that are uploaded before 11h00 (11am) on Monday, January 27. After that late-submission date, the exercise is worth zero marks (but it must still be completed - see the course outline). The deliverables for this exercise are to be uploaded by anonymous FTP only. No paper. The exact anonymous FTP address to which you must connect is: ftp ftp.ncf.ca (If you can't connect to that site due to Carleton/FreeNet network problems, you may use machine ftp.algonquincollege.com. You will find the two files you need under directory pub/alleni/dat2330 and you may upload your answer to the "uploads" directory there.) See your Linux text p.170 for an example of how to use "anonymous" FTP. The week03notes.txt file also contains a practice anonymous FTP session. Exercise Synopsis: Download some files. Create several new files containing different information. Concatenate the files together into one big file. Upload the big file to the FTP server via anonymous FTP. Where to work: You can download and create the files for this exercise on any network-connected Unix machine. If you work on ACADUNIX (via telnet or ssh), the files you work on remain there even after you log off. If you work on Floppix, make sure you use FTP to transfer anything you want to keep from Floppix to your account on ACADUNIX to save it before you shut down Floppix and memory is erased. Always keep a spare copy of your exercises! WARNING: Do not attempt this exercise on a Windows machine - the text file format is different. You must work on Unix/Linux. How to create the answer files: How do you create a multi-line text file, if you haven't read ahead and learned the "vi" text editor? Given what you know so far this term, you can create multi-line files in any of several different ways. Choose a method: Method A: Use the echo command to echo each line into its own file name. Use the "cat" command to catenate all files into one big file. $ echo Line one. >f1 $ echo Line two. >f2 $ echo Line three. >f3 $ cat f1 f2 f3 >out Method B: Use the "cat" command with output redirected as shown at the top of page 97 in your Linux text. $ cat >out Line 1. Line 2. Line 3. ^D (type CONTROL-D to signal EOF here) Method C: Use the echo command with the "append" function of the shell (">>") to append lines to a file (see your Linux text, p.100). $ echo Line one. >out $ echo Line two. >>out $ echo Line three. >>out Note that only the first line containing ">out" erases the file. The other lines ">>out" append data to the end of the file. Exercise Details: 1. Create a file named file1.txt containing the lines of the Exterior Assignment Submission label, following the example you will find under the "Assignment Standards" button on my teaching home page (www.idallen.com/teaching). For full marks, follow the directions for the label exactly. The label has exactly 7 lines, plus an optional Comments line. I use a program to find these lines; the spelling of the label fields on all the lines must be exactly as shown. (Make sure to include the label field names as well as the data.) 2. Use anonymous FTP to the above ftp.ncf.ca site to download the file right-to-read.txt from under the "aa610/pub" directory. 3. Use Unix command(s) to extract just the first two lines from the right-to-read.txt file and redirect the output into a new file named "file2.txt". (Do not enter the quotes as part of any file names.) File file2.txt will contain exactly two lines. (Recall that the "wc" command will count the lines, words, and characters in a file.) 4. From the same right-to-read.txt file, use Unix commands to extract lines 133 to 146 (inclusive) from this file into a file named "file3.txt". (Hint: Extract the first 146 lines from the file, then extract the last 14 lines from those lines.) The resulting file ("file3.txt") must be 14 lines long. 5. Use anonymous FTP to the above ftp.ncf.ca site to download the file can-you-trust.txt from under the "aa610/pub" directory. 6. Use Unix commands to extract lines 172 to 189 (inclusive) from the can-you-trust.txt file into a new file named "file4.txt". 7. Concatenate your four files (file1.txt through file4.txt) together and redirect the output into a new single file named "myout.txt". File myout.txt will contain the contents of all four files in one file, with text from file1.txt on the top and the text from file4.txt on the bottom. (Shortcut: Use a GLOB wildcard to match the four file names.) 8. Redirect the output of "ls -li myout.txt" into a file named "file5.txt". (Make sure your file is named "myout.txt".) 9. Concatenate the two files myout.txt and file5.txt together into a new file named "answer.txt". File answer.txt will contain the contents of myout.txt and file5.txt together in one file, with the text from myout.txt on the top and the text from file5.txt on the bottom. 10. Rename "answer.txt" to be a file name that is your Algonquin userid followed by a period followed by five or more random letters that you choose, e.g. names like "abcd0001.iandallen" or "abcd0001.x7075". You choose the random characters. Write down what you chose, so you remember. You will be uploading this file. 11. Use anonymous FTP to upload your renamed file to the "aa610/uploads" directory on the above ftp.ncf.ca FTP site. You will not be able to see your file in the uploads directory after you have uploaded it - the directory is protected. Your FTP "put" statistics will tell you if the transfer worked. It will say: "Transfer complete." If you remember the file name, you can fetch it back again ("get") to verify the uploaded contents. I will acknowledge the receipt of your upload shortly after the due date, by return email to the Algonquin email account found in the Assignment Submission label in the uploaded file. If you don't get an acknowledgement, then either your submission did not arrive, or it was missing a submission label, or the label or email was invalid. You won't get any acknowledgement by return email if you submit your answers after the original due date. If you have problems, see me in a lab or post questions to the discussion news group.