IRC log of #novawebdev for Friday, 2023-11-03

*** 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
ubuntouristhi tboimah and mulbah 13:03
tboimahGood morning ubuntourist13:03
mulbahGood morning Mr. Cole13:03
ubuntouristtboimah, it took some time to get through the script movie of your homework but I sent a reply yesterday.13:03
tboimahyes i saw it13:04
ubuntouristmulbah, 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
ubuntouristA 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
ubuntouristscript and scriptreplay are very standard and included in most Linux systems automatically, but I am beginning to think that13:06
ubuntouristthere 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
ubuntouristSo, mulbah have you seen the assignment and started working on it yet?13:07
mulbahit's today I'm on computer my computer is giving problem let me check I'm using one of the machine in the lab13:09
ubuntouristIt is hard for me to move forward unless the two of you are moving at the same speed.13:10
mulbahI was reading on the cut command13:11
mulbahand I understand somethings about it13:11
ubuntouristIf 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
ubuntouristThe 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
ubuntouristI was looking at the school curriculum for grades 1 to 12 in Liberia. According to the Ministry of Education,13:14
ubuntouristyou have both studied biology, chemistry and physics. Is that correct?13:14
tboimah+113:15
mulbahMr. Cole first what I was understanding in the cut command was the different between fields and delimiters13:15
mulbah=13:15
mulbah+113:15
mulbahbut I read on it and understand it13:16
ubuntouristmulbah, the cut command can divide lines by chacacters -- it uses the "-b" for "bytes" which, on computers is usually synonymous to characters13:17
ubuntouristmulbah, 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
ubuntouristIf your science classses are similar to those in the United States, you will have some experience with performing experiments13:19
ubuntouristand collecting data from your experiments, and then recording the data and making graphs from the results.13:20
ubuntouristtboimah, mulbah, was that part of your biology, chemistry or physics classses? Lab work?13:20
mulbahYeah13:22
tboimah+113:22
mulbahbut it was very hard for us to make use of the lab13:22
ubuntouristOK. Good.  So, you would create a table with rows and columns and jot down numbers...13:23
ubuntouristFor example, maybe measuring temperature changes over time, 13:24
ubuntouristYou would have a series of two values, and when you graph them, the X axis might be "time"13:25
ubuntouristand the Y axis might be "temperature".13:25
ubuntouristTime and temperature in that experiment would be fields in a computer program.13:25
ubuntouristTo store the values in a computer file, you would put pairs of values on separate lines:13:26
ubuntourist10:00     20C13:26
ubuntourist10:01    22C13:27
ubuntourist10:02    25C13:27
ubuntourist...13:27
ubuntouristMaybe something would change color or weight too. Then you would have three or four values on each line.13:28
ubuntouristYou could separate the values any way you like:13:28
mulbahthe pairs of values is the fields and tap is the delimiter13:28
ubuntourist10:00,20C13:28
ubuntourist10:01,22C13:28
ubuntourist10:02,25C13:29
ubuntourist...13:29
ubuntouristor13:29
ubuntourist10:00x20C13:29
ubuntourist10:01x22C13:29
ubuntourist10:02x25C13:29
ubuntourist...13:29
ubuntouristBut, you would want to use the same delimiter through the file.13:30
ubuntouristmulbah, yes. Exactly.13:30
ubuntouristSo, when you are looking at the three files that I gave in the homework, the idea is to find the BEST character to use13:31
ubuntouristas a delimiter.. When you look at the files, which character on the line will break the line into useful, meaningful parts?13:32
ubuntouristDifferent 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
ubuntouristIf you encounter files with names like accounts.csv or data.csv or census.csv, the "CSV" means "comma-separated-values"13:34
ubuntouristwhich means exactly what it says: values (field data) are separated (delimited) using commas.13:35
ubuntouristBut, what if some of the values require a comma as part of the value? 13:36
ubuntouristIn that situation, you cannot use the comma as both data and the delimiter.13:36
ubuntouristIn 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
ubuntouristSo if I write $100,000  I mean one hundred thousand dollars.13:39
ubuntouristSuppose I have dates and dollar amounts:13:39
ubuntourist10/10/2023,100,00013:40
ubuntouristwould be bad. Comma is a badd delimiter here.13:40
ubuntouristbecause the line would break into three fields    10/10/2023         100           00013:41
ubuntouristSlash is not the delimiter either, because then you end up with meaningless data again:13:41
ubuntourist10         10            2023,100,00013:42
ubuntouristSo, the delimiter would need to be some character that is not used for data in this file.13:42
ubuntouristLets all go to a tmate session.13:43
sysadmin_should we tmate13:43
sysadmin_?13:43
ubuntouristI like using the server for this, because we can all join it.13:43
ubuntouristI'll start it. Hold13:43
ubuntouristssh YAfv4wKA698FxdyQjuhFXSBQf@lon1.tmate.io13: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
ubuntouristLooking at the tmate, what is the BEST delimiter for what you are seeing?13:46
ubuntouristWhich character breaks the lines into logical, meaningful parts?13:47
tboimahI think it will be ":"13:47
ubuntouristtboimah, Yes!13:48
ubuntouristBefore continuing, I want the log to show: We were just looking at /etc/passwd13:50
ubuntouristand tboimah said the delimiter was a ":" -- in case you are reviewing the logs later.13:50
tboimahyeah13:51
ubuntouristNow we're looking at /usr/share/doc/vim/copyright13:51
ubuntouristThis one is a little "stupider" and maybe I should not have used it as an example.13:51
ubuntouristBut the idea is to be flexible in your thinking. You will often need to make an educated guess when13:52
ubuntouristyou are looking at a file that you have never seen before.13:52
ubuntouristIn this file, just looking at what is on the screen now, without scrolling, what is the most logical way13:53
ubuntouristto 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
tboimahThat will be "tab" or "space"13:55
ubuntouristtboimah, correct (mostly) again. We cannot have two delimiters -- at least not at the same time,13:56
ubuntouristwhen using cut.  So "space" would be the best choice here. "tab" does not appear on every line, and13:57
tboimahOkay13:57
ubuntouristwhen i(or if) it does appear, it would probably split the line wrong:13:57
ubuntouristIf the lines at the top that have a year and then a name start with a tab, 13:58
ubuntouristit is probably the only tab on the line. So the entire line would consist of an empty field, followed by a tab13:59
ubuntouristfollowed by the entire rest of the line.13:59
ubuntouristAnd tboimah you already got this one (/var/lib/dpkg/info/vim.list) right in the homework,14:00
tboimahyeah the it will be "/"14:01
ubuntouristOk.14:01
ubuntouristThe OTHER part of the assignment was to be able to get groups of fields, and skip fields with cut.14:02
ubuntouristSo, for example fields 2 to 3, and field 5 but not field 4. 14:02
ubuntouristthe manual page for cut "man cut" describes how you can get groups of bytes (-b) or groups of fields (-f) by 14:03
ubuntouristlisting numbers after the -b or -f in different ways.14:04
ubuntouristYou can "cherry-pick" characters or fields using dash to get several consecutive fields, or14:05
ubuntouristcomma 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 immediately14:06
ubuntouristafter the other, in sequence. 1,2,3,4 are "consecutive".  1,4,7,9 are not consecutive. not continuous. There are gaps14:07
ubuntouristbetween the numbers.14:07
ubuntouristOh, I don't remember if I mentioned it in my response to you tboimah but you can make your answers simpler:14:08
ubuntouristinstead of14:08
ubuntouristcat /etc/passwd | cut -f 1 -d ":"14:09
ubuntouristyou can type:14:09
ubuntouristcut -f 1 -d ":" /etc/passwd14:09
ubuntouristyour way worked, but usually, if a command accepts a pipe, it will also accept a file name directly.14:10
ubuntouristputting the file name at the end of the cut command saves a little bit of typing.14:11
ubuntouristOne thing to be careful about with delimiters: remember, if there are two delimiters next to each other,14:12
ubuntouristor, if the line starts with a delimiter or ends with a delimiter, there is an extra "empty" field with no data.14:13
tboimahthe connection close can you please send another ssh link please.14:13
ubuntouristFor example, using a comma field delimiter:14:13
ubuntourist,30,22,,13,14:14
ubuntouristthe fields above are:14:14
ubuntourist""   "30"   "22"   ""   "13"   ""14:14
ubuntouristsix fields.14:15
ubuntouristUnderstand?14:15
ubuntouristssh DZ9N7WZ4qFVNaDHSM5TCJX8Et@lon1.tmate.io14:17
ubuntouristACTION waits for confirmation of understanding...14:17
tboimahwell understood14:18
ubuntouristOK.14:18
ubuntouristThere's a way to fix PART of that problem...14:18
ubuntouristFirst I'm going to use the copyright file to see if it exhibits the problem.14:19
ubuntouristI think it will: If there are many occurrances of spaces that have no text between them, then14:20
ubuntouristwe will have many empty fields.14:20
ubuntouristI'm going to come up with a better example... That didn't illustrate what I was hoping.14:23
ubuntouristOK. There's a simple example: oops.py14:24
ubuntouristLet's use space as the delimiter and get the second field.14:25
ubuntouristAnyone care to try it?14:25
tboimahyeah let me try14:25
ubuntouristmulbah, do you think you can do the cut?14:25
ubuntouristtboimah, give mulbah  a chance14:25
tboimahOkay14:26
mulbahokay let me try14:26
ubuntouristmulbah, second field, not first...14:28
mulbahokay14:28
ubuntouristAnd for three lines, no need for most14:28
ubuntouristit will all fit on one screen.14:28
mulbahdone 14:29
ubuntouristOK. So that's the right command, but it shows the problem: 14:29
ubuntouristBecause python uses spaces for indenting, the second and third line of the file14:29
ubuntouriststarts with FOUR spaces: That means there are four empty fields!14:30
ubuntouristSometimes, you want to eliminate the empty fields when trying to cut.14:30
ubuntouristNEW COMMAND TIME !!! OH BOY, MY FAVORITE !!!  14:31
ubuntouristThere is a "translate" command -- "tr". (I think it is for "translate".)14:32
ubuntouristYup. "man tr" said it was translate14:32
ubuntouristIt doesn't really "translate" in the way we normally use the word. It replaces sets of14:33
ubuntouristcharacters with other sets of characters.14:34
ubuntouristFor example, if I wanted to see "oops.py" in all upper-case, then I want to translate all "a" to "A"14:34
ubuntouristall "b" to "B" and on to "z" to "Z".14:35
ubuntouristtr "a-z" "A-Z" oops.py14:35
ubuntouristOops on oops.py... My mistake...14:36
ubuntouristAh, here is an example of a program that ONLY works with the pipe.14:36
ubuntouristWe need to do it the way you tboimah did for cut:14:36
ubuntouristcat then pipe then tr14:37
mulbahwow14:37
ubuntouristBut, for using it with cut, our goal is to "squeeze" the file: We want to take14:38
ubuntouristmultiple spaces and "squeeze" them into one space14:39
ubuntourist"-s" for "squeeze"14:39
ubuntouristIt's still not perfect but it is a lot bettter now:14:41
ubuntouristI wanted the second "word" on each line (second field).14:41
ubuntouristBut because some lines start with four spaces that we squeezed down to one,14:42
ubuntouristwe still have an empty field at the start.14:42
ubuntouristSo, the second and third lines show "print..." which is the first word, but the second field.14:43
ubuntouristThere's a way to solve that with special editor called a "stream editor" -- sed.14:44
ubuntouristsed is a little like vim. vim has a "substitution" command that works with our friend regular expressions...14:45
ubuntouristI might get this wrong: I am not a "sed" expert, and I am not a "vim" expert...14:45
ubuntouristIt did the right thing, but I confess: I am baffled by the third line.14:48
ubuntouristI was expecting the third line to be empty...14:49
ubuntouristI used "sed" and a regular expression substitution that took "^ " -- a space at the beginning of the line,14:49
ubuntouristand substitued nothing. s/^ //;   should replace the space with nothing. It should eliminate the space.14:50
ubuntouristIt did that correctly: We can see that the second line printed "next"14:51
ubuntouristthe first field -- after eliminating the space at the beginning of the line is14:51
ubuntouristprint("The14:51
ubuntouristand the second field would be "next"14:52
ubuntouristbut for the third line, the first field is now "print(i)" and there is no second field... I do not know why14:52
ubuntouristit 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
ubuntouristwe will look more at sed in the future, but for now,14:54
ubuntouristpart of the homework remains:14:54
ubuntouristRe-read my assignment, and look at the man page for cut ("man cut"). Study the kinds of14:55
ubuntouristarguments that can follow "-b" and "-f": The goal is to print groups of fields while skipping other fields.14:56
ubuntouristYou 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
ubuntouristUse /etc/passwd as the file.14:58
ubuntouristGot it?14:58
mulbahokay14:58
tboimahyes14:58
ubuntouristOK. Good luck!14:58
ubuntouristOnce 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
ubuntouristSee you on Monday!15:00
tboimahOkay, 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/!