*** scooper has quit (Quit: Leaving) | 03:15 | |
*** ledmer has quit (Remote host closed the connection) | 04:00 | |
*** ledmer has quit (Read error: Connection reset by peer) | 04:36 | |
*** scooper has quit (Ping timeout: 480 seconds) | 10:21 | |
*** scooper has quit (None) | 11:08 | |
*** sysadmin has quit (Ping timeout: 480 seconds) | 11:14 | |
ubuntourist | hi tboimah and mulbah | 13:03 |
---|---|---|
tboimah | Good morning ubuntourist | 13:03 |
mulbah | Good morning Mr. Cole | 13:03 |
ubuntourist | tboimah, it took some time to get through the script movie of your homework but I sent a reply yesterday. | 13:03 |
tboimah | yes i saw it | 13:04 |
ubuntourist | mulbah, I haven't seen your answers yet. (It does not need to be a script movie. I only need the commands and the output. | 13:04 |
ubuntourist | A movie may be the easiest way to create that, but they can be s-l-o-w to watch. So it will take me time to respond to those.) | 13:05 |
ubuntourist | script and scriptreplay are very standard and included in most Linux systems automatically, but I am beginning to think that | 13:06 |
ubuntourist | there may be an apt package that is not automatically included but will do a better job. (I've found two or three possibilities that I need to test.) | 13:07 |
ubuntourist | So, mulbah have you seen the assignment and started working on it yet? | 13:07 |
mulbah | it's today I'm on computer my computer is giving problem let me check I'm using one of the machine in the lab | 13:09 |
ubuntourist | It is hard for me to move forward unless the two of you are moving at the same speed. | 13:10 |
mulbah | I was reading on the cut command | 13:11 |
mulbah | and I understand somethings about it | 13:11 |
ubuntourist | If I repeat everything I've said to you ( mulbah ) then tboimah will sit bored. If I continue with tboimah then you will be confused. | 13:12 |
ubuntourist | The problem was that I still am not finding a good way to explain fields and field delimiters. You are both struggliing with it. | 13:13 |
ubuntourist | I was looking at the school curriculum for grades 1 to 12 in Liberia. According to the Ministry of Education, | 13:14 |
ubuntourist | you have both studied biology, chemistry and physics. Is that correct? | 13:14 |
tboimah | +1 | 13:15 |
mulbah | Mr. Cole first what I was understanding in the cut command was the different between fields and delimiters | 13:15 |
mulbah | = | 13:15 |
mulbah | +1 | 13:15 |
mulbah | but I read on it and understand it | 13:16 |
ubuntourist | mulbah, the cut command can divide lines by chacacters -- it uses the "-b" for "bytes" which, on computers is usually synonymous to characters | 13:17 |
ubuntourist | mulbah, or cut can be used to divide lines into fields using "-f" and "-d" together. So it is important to understand both the cut command and the concept of fields. | 13:18 |
ubuntourist | If your science classses are similar to those in the United States, you will have some experience with performing experiments | 13:19 |
ubuntourist | and collecting data from your experiments, and then recording the data and making graphs from the results. | 13:20 |
ubuntourist | tboimah, mulbah, was that part of your biology, chemistry or physics classses? Lab work? | 13:20 |
mulbah | Yeah | 13:22 |
tboimah | +1 | 13:22 |
mulbah | but it was very hard for us to make use of the lab | 13:22 |
ubuntourist | OK. Good. So, you would create a table with rows and columns and jot down numbers... | 13:23 |
ubuntourist | For example, maybe measuring temperature changes over time, | 13:24 |
ubuntourist | You would have a series of two values, and when you graph them, the X axis might be "time" | 13:25 |
ubuntourist | and the Y axis might be "temperature". | 13:25 |
ubuntourist | Time and temperature in that experiment would be fields in a computer program. | 13:25 |
ubuntourist | To store the values in a computer file, you would put pairs of values on separate lines: | 13:26 |
ubuntourist | 10:00 20C | 13:26 |
ubuntourist | 10:01 22C | 13:27 |
ubuntourist | 10:02 25C | 13:27 |
ubuntourist | ... | 13:27 |
ubuntourist | Maybe something would change color or weight too. Then you would have three or four values on each line. | 13:28 |
ubuntourist | You could separate the values any way you like: | 13:28 |
mulbah | the pairs of values is the fields and tap is the delimiter | 13:28 |
ubuntourist | 10:00,20C | 13:28 |
ubuntourist | 10:01,22C | 13:28 |
ubuntourist | 10:02,25C | 13:29 |
ubuntourist | ... | 13:29 |
ubuntourist | or | 13:29 |
ubuntourist | 10:00x20C | 13:29 |
ubuntourist | 10:01x22C | 13:29 |
ubuntourist | 10:02x25C | 13:29 |
ubuntourist | ... | 13:29 |
ubuntourist | But, you would want to use the same delimiter through the file. | 13:30 |
ubuntourist | mulbah, yes. Exactly. | 13:30 |
ubuntourist | So, when you are looking at the three files that I gave in the homework, the idea is to find the BEST character to use | 13:31 |
ubuntourist | as a delimiter.. When you look at the files, which character on the line will break the line into useful, meaningful parts? | 13:32 |
ubuntourist | Different files use different delimiters. For example, a comma is often a good delimiter. It is so common that there is even a file extension for it: | 13:33 |
ubuntourist | If you encounter files with names like accounts.csv or data.csv or census.csv, the "CSV" means "comma-separated-values" | 13:34 |
ubuntourist | which means exactly what it says: values (field data) are separated (delimited) using commas. | 13:35 |
ubuntourist | But, what if some of the values require a comma as part of the value? | 13:36 |
ubuntourist | In that situation, you cannot use the comma as both data and the delimiter. | 13:36 |
ubuntourist | In the US, when we write large numbers, we use a comma as an indicator of thousands, millions, billions, etc. | 13:37 |
ubuntourist | (I know other countries use different idicators. I am suspecting that Liberia uses the US standards, due to the history of Liberia.) | 13:38 |
ubuntourist | So if I write $100,000 I mean one hundred thousand dollars. | 13:39 |
ubuntourist | Suppose I have dates and dollar amounts: | 13:39 |
ubuntourist | 10/10/2023,100,000 | 13:40 |
ubuntourist | would be bad. Comma is a badd delimiter here. | 13:40 |
ubuntourist | because the line would break into three fields 10/10/2023 100 000 | 13:41 |
ubuntourist | Slash is not the delimiter either, because then you end up with meaningless data again: | 13:41 |
ubuntourist | 10 10 2023,100,000 | 13:42 |
ubuntourist | So, the delimiter would need to be some character that is not used for data in this file. | 13:42 |
ubuntourist | Lets all go to a tmate session. | 13:43 |
sysadmin_ | should we tmate | 13:43 |
sysadmin_ | ? | 13:43 |
ubuntourist | I like using the server for this, because we can all join it. | 13:43 |
ubuntourist | I'll start it. Hold | 13:43 |
ubuntourist | ssh YAfv4wKA698FxdyQjuhFXSBQf@lon1.tmate.io | 13:44 |
*** tboimah has quit (Ping timeout: 480 seconds) | 13:45 | |
*** dcammue has quit (Ping timeout: 480 seconds) | 13:45 | |
*** mulbah has quit (Ping timeout: 480 seconds) | 13:45 | |
ubuntourist | Looking at the tmate, what is the BEST delimiter for what you are seeing? | 13:46 |
ubuntourist | Which character breaks the lines into logical, meaningful parts? | 13:47 |
tboimah | I think it will be ":" | 13:47 |
ubuntourist | tboimah, Yes! | 13:48 |
ubuntourist | Before continuing, I want the log to show: We were just looking at /etc/passwd | 13:50 |
ubuntourist | and tboimah said the delimiter was a ":" -- in case you are reviewing the logs later. | 13:50 |
tboimah | yeah | 13:51 |
ubuntourist | Now we're looking at /usr/share/doc/vim/copyright | 13:51 |
ubuntourist | This one is a little "stupider" and maybe I should not have used it as an example. | 13:51 |
ubuntourist | But the idea is to be flexible in your thinking. You will often need to make an educated guess when | 13:52 |
ubuntourist | you are looking at a file that you have never seen before. | 13:52 |
ubuntourist | In this file, just looking at what is on the screen now, without scrolling, what is the most logical way | 13:53 |
ubuntourist | to split the lines currently shown? | 13:53 |
ubuntourist | (It will be a character that is common to ALL of the lines.) | 13:54 |
*** dcammue_ has quit (Quit: Leaving) | 13:55 | |
tboimah | That will be "tab" or "space" | 13:55 |
ubuntourist | tboimah, correct (mostly) again. We cannot have two delimiters -- at least not at the same time, | 13:56 |
ubuntourist | when using cut. So "space" would be the best choice here. "tab" does not appear on every line, and | 13:57 |
tboimah | Okay | 13:57 |
ubuntourist | when i(or if) it does appear, it would probably split the line wrong: | 13:57 |
ubuntourist | If the lines at the top that have a year and then a name start with a tab, | 13:58 |
ubuntourist | it is probably the only tab on the line. So the entire line would consist of an empty field, followed by a tab | 13:59 |
ubuntourist | followed by the entire rest of the line. | 13:59 |
ubuntourist | And tboimah you already got this one (/var/lib/dpkg/info/vim.list) right in the homework, | 14:00 |
tboimah | yeah the it will be "/" | 14:01 |
ubuntourist | Ok. | 14:01 |
ubuntourist | The OTHER part of the assignment was to be able to get groups of fields, and skip fields with cut. | 14:02 |
ubuntourist | So, for example fields 2 to 3, and field 5 but not field 4. | 14:02 |
ubuntourist | the manual page for cut "man cut" describes how you can get groups of bytes (-b) or groups of fields (-f) by | 14:03 |
ubuntourist | listing numbers after the -b or -f in different ways. | 14:04 |
ubuntourist | You can "cherry-pick" characters or fields using dash to get several consecutive fields, or | 14:05 |
ubuntourist | comma to get non-consecutive fields, or both in combination. | 14:05 |
ubuntourist | (Before I go on, I realize there are differences in vocabulary sometimes. "consecutive" means one immediately | 14:06 |
ubuntourist | after the other, in sequence. 1,2,3,4 are "consecutive". 1,4,7,9 are not consecutive. not continuous. There are gaps | 14:07 |
ubuntourist | between the numbers. | 14:07 |
ubuntourist | Oh, I don't remember if I mentioned it in my response to you tboimah but you can make your answers simpler: | 14:08 |
ubuntourist | instead of | 14:08 |
ubuntourist | cat /etc/passwd | cut -f 1 -d ":" | 14:09 |
ubuntourist | you can type: | 14:09 |
ubuntourist | cut -f 1 -d ":" /etc/passwd | 14:09 |
ubuntourist | your way worked, but usually, if a command accepts a pipe, it will also accept a file name directly. | 14:10 |
ubuntourist | putting the file name at the end of the cut command saves a little bit of typing. | 14:11 |
ubuntourist | One thing to be careful about with delimiters: remember, if there are two delimiters next to each other, | 14:12 |
ubuntourist | or, if the line starts with a delimiter or ends with a delimiter, there is an extra "empty" field with no data. | 14:13 |
tboimah | the connection close can you please send another ssh link please. | 14:13 |
ubuntourist | For example, using a comma field delimiter: | 14:13 |
ubuntourist | ,30,22,,13, | 14:14 |
ubuntourist | the fields above are: | 14:14 |
ubuntourist | "" "30" "22" "" "13" "" | 14:14 |
ubuntourist | six fields. | 14:15 |
ubuntourist | Understand? | 14:15 |
ubuntourist | ssh DZ9N7WZ4qFVNaDHSM5TCJX8Et@lon1.tmate.io | 14:17 |
ubuntourist | ACTION waits for confirmation of understanding... | 14:17 |
tboimah | well understood | 14:18 |
ubuntourist | OK. | 14:18 |
ubuntourist | There's a way to fix PART of that problem... | 14:18 |
ubuntourist | First I'm going to use the copyright file to see if it exhibits the problem. | 14:19 |
ubuntourist | I think it will: If there are many occurrances of spaces that have no text between them, then | 14:20 |
ubuntourist | we will have many empty fields. | 14:20 |
ubuntourist | I'm going to come up with a better example... That didn't illustrate what I was hoping. | 14:23 |
ubuntourist | OK. There's a simple example: oops.py | 14:24 |
ubuntourist | Let's use space as the delimiter and get the second field. | 14:25 |
ubuntourist | Anyone care to try it? | 14:25 |
tboimah | yeah let me try | 14:25 |
ubuntourist | mulbah, do you think you can do the cut? | 14:25 |
ubuntourist | tboimah, give mulbah a chance | 14:25 |
tboimah | Okay | 14:26 |
mulbah | okay let me try | 14:26 |
ubuntourist | mulbah, second field, not first... | 14:28 |
mulbah | okay | 14:28 |
ubuntourist | And for three lines, no need for most | 14:28 |
ubuntourist | it will all fit on one screen. | 14:28 |
mulbah | done | 14:29 |
ubuntourist | OK. So that's the right command, but it shows the problem: | 14:29 |
ubuntourist | Because python uses spaces for indenting, the second and third line of the file | 14:29 |
ubuntourist | starts with FOUR spaces: That means there are four empty fields! | 14:30 |
ubuntourist | Sometimes, you want to eliminate the empty fields when trying to cut. | 14:30 |
ubuntourist | NEW COMMAND TIME !!! OH BOY, MY FAVORITE !!! | 14:31 |
ubuntourist | There is a "translate" command -- "tr". (I think it is for "translate".) | 14:32 |
ubuntourist | Yup. "man tr" said it was translate | 14:32 |
ubuntourist | It doesn't really "translate" in the way we normally use the word. It replaces sets of | 14:33 |
ubuntourist | characters with other sets of characters. | 14:34 |
ubuntourist | For example, if I wanted to see "oops.py" in all upper-case, then I want to translate all "a" to "A" | 14:34 |
ubuntourist | all "b" to "B" and on to "z" to "Z". | 14:35 |
ubuntourist | tr "a-z" "A-Z" oops.py | 14:35 |
ubuntourist | Oops on oops.py... My mistake... | 14:36 |
ubuntourist | Ah, here is an example of a program that ONLY works with the pipe. | 14:36 |
ubuntourist | We need to do it the way you tboimah did for cut: | 14:36 |
ubuntourist | cat then pipe then tr | 14:37 |
mulbah | wow | 14:37 |
ubuntourist | But, for using it with cut, our goal is to "squeeze" the file: We want to take | 14:38 |
ubuntourist | multiple spaces and "squeeze" them into one space | 14:39 |
ubuntourist | "-s" for "squeeze" | 14:39 |
ubuntourist | It's still not perfect but it is a lot bettter now: | 14:41 |
ubuntourist | I wanted the second "word" on each line (second field). | 14:41 |
ubuntourist | But because some lines start with four spaces that we squeezed down to one, | 14:42 |
ubuntourist | we still have an empty field at the start. | 14:42 |
ubuntourist | So, the second and third lines show "print..." which is the first word, but the second field. | 14:43 |
ubuntourist | There's a way to solve that with special editor called a "stream editor" -- sed. | 14:44 |
ubuntourist | sed is a little like vim. vim has a "substitution" command that works with our friend regular expressions... | 14:45 |
ubuntourist | I might get this wrong: I am not a "sed" expert, and I am not a "vim" expert... | 14:45 |
ubuntourist | It did the right thing, but I confess: I am baffled by the third line. | 14:48 |
ubuntourist | I was expecting the third line to be empty... | 14:49 |
ubuntourist | I used "sed" and a regular expression substitution that took "^ " -- a space at the beginning of the line, | 14:49 |
ubuntourist | and substitued nothing. s/^ //; should replace the space with nothing. It should eliminate the space. | 14:50 |
ubuntourist | It did that correctly: We can see that the second line printed "next" | 14:51 |
ubuntourist | the first field -- after eliminating the space at the beginning of the line is | 14:51 |
ubuntourist | print("The | 14:51 |
ubuntourist | and the second field would be "next" | 14:52 |
ubuntourist | but for the third line, the first field is now "print(i)" and there is no second field... I do not know why | 14:52 |
ubuntourist | it did not produce an empty line. It looks like I need to review the man page for "cut" | 14:53 |
ubuntourist | (It seems that if "cut" does not find any field delimiter, it prints the entire line.) | 14:53 |
ubuntourist | we will look more at sed in the future, but for now, | 14:54 |
ubuntourist | part of the homework remains: | 14:54 |
ubuntourist | Re-read my assignment, and look at the man page for cut ("man cut"). Study the kinds of | 14:55 |
ubuntourist | arguments that can follow "-b" and "-f": The goal is to print groups of fields while skipping other fields. | 14:56 |
ubuntourist | You don't need to do it for all three files. Just demonstrate that you can print fields 2 to 4, skip 5 and print 6 to 8 all on one line. | 14:57 |
ubuntourist | Use /etc/passwd as the file. | 14:58 |
ubuntourist | Got it? | 14:58 |
mulbah | okay | 14:58 |
tboimah | yes | 14:58 |
ubuntourist | OK. Good luck! | 14:58 |
ubuntourist | Once you have done that, we'll be ready to explore some of those other commands, | 14:59 |
ubuntourist | (paste, head, tail, tr, rev, tac) that I mentioned in the end of the assignment. But first, get very comfortable with "cut". | 15:00 |
ubuntourist | See you on Monday! | 15:00 |
tboimah | Okay, thanks for today and have a nice day. | 15:00 |
*** ubuntourist has quit (Quit: Leaving) | 15:01 | |
*** tboimah has quit (Quit: Leaving) | 15:01 | |
*** mulbah has quit (Quit: Leaving) | 15:25 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!