 I am going to continue with using Linux tools. So, let me introduce our colleagues, there is Shrikan Patnaik here, who is also in the Fossey project and there is also Prashant the way here. So, they both also will help in the conducting of these sessions. So, our next topic called cut, which we will do for cut and paste is what Shrikan will continue. Before he starts, there is one particular point I would like to speak about that Shrikan can speak a little more about is about the editor to use. So, all these files were using for viewing, we saw the food or text, we saw one other file, these are all just text files. So, for all these batch scripting etcetera, we are going to write just plain text files. We are not going to open any editors, any fancy editors for that. So, I am not trying to say that only Microsoft Word is bad for this purpose. To write a plain file also open office Word is not the right editor, to write a just a plain file. So, let me give an example. So, let us see the screen, so we have this bar dot text, bar dot text is what we can see using less we said, this is some line, we can also cat bar dot text that information comes on the screen and as I said the prompt again comes at the end of after showing all this information on the screen. But this is some file that is not written using open office, it is not written using Microsoft Word, it is edited using a very simple editor. For example, so for those who have not used a very simple plain text editor, we would recommend that you just start with nano, nano bar dot text is a editor that nano editor itself default comes in all Linux systems. So, nano will open such an editor and then you can type whatever is required. So, this is how you can type various things, then at the bottom, at the bottom it says how do you write an exit etcetera, so control X for exit when it says now it will say do you want to save it, so we can again save it to the same file name and then now if you do cat bar dot text, we see that all this information we typed is also there on the screen. So, this simple editor is what we really want to encourage the use of, why because then people want to write something and send an email, then they write it in a doc file or a word using a word document, it is not essential for just plain text, it increases the overhead on everything. So, with that I would, so how to do cut paste copy of text files is what we will start seeing now. So, these are not cut paste using a mouse, this is not using how to do cut paste of documents that are written in word or doc, this is just plain text files, Srikant will continue now. Hello everyone, I am Srikant and I will take the session from now. So, now we will see some editing commands in Linux. So, you can see on the screen there is a cut command on the slide. So, it says that it allow you to view a certain section of lines. So, for example, we are taking here say ETC password, see you can see there is a slash is there, the slash means it is the root directory, after that we have ETC, ETC is a folder which contains the configuration files. So, in that case the file is password, you can see P A double S W T. So, what you will see we will just try to view the content of password file. So, for that you can use any editor for now to just view the files we are using cat. So, cat slash ETC slash pass and then I press tab to complete it automatically. So, you can see these are the output of cat command. So, it is very difficult to view the certain sections of the file like you can see there is an IITB return, X is written and you can see every field is separated by a column, see every field is separated by a column like thousand one thousand one IITB comma different things are there. So, what is our aim is to view only certain sections of the file like suppose we want only the first line of the file which contains the username. So, now with the help of cut command we will try to remove that other lines and just view the first line. In this case we have the first line as root you can see it is a root. So, may be it is not visible properly on your terminal output because we increase the font size. So, if you view on the normal terminal you will see the lines like this root colon X colon 0 colon like that. So, in the next command we will show how to just view the first column of the page the first column we have root second column we have X. So, we will call this as first field and this second that is X we call as second field. So, so on this is third fourth fifth like that and you can see each field is separated by a colon. So, if you go and type man cut you can see different options which cut provides. So, cut has different options as you can see like hyphen B hyphen C hyphen B is to select the number of bytes that we would not see now you can explore by your own. So, what we are interested is we are interested in hyphen D it says it is a delimiter instead of tab field delimiter. So, by default if you do not provide hyphen D option the cut command will separate the file using the tab space, but we do not want in our case because in our case we have to tell the cut command that we are having a file which contains the colon instead of tab. So, in the command now I will show you command to exit the terminal from the man mode man just type Q. So, to clear you know that control L it will clear the screen. Now just type the command cut hyphen D. So, first field we want only the username first field give the colon as a delimiter hyphen F we will see what is hyphen F first is the field number then slash ETC slash password. So, before entering I want to say that what are these different commands. So, as I already told cut is a command which will use to cut a certain field in the file hyphen D is the delimiter. So, we are forcing the file forcing the command to parse on colon and hyphen F is the field. So, which field we want we want first field as you can see first field is the root that is a username enter. So, now instead of that big file with different colons and different numbers you are getting only the names and this is what we want you can see all the names are listed like root, daemon, bin, these all are username names in Unix. So, again let us see the command it is cut hyphen D colon hyphen F 1. So, if you give instead of hyphen F 1 you just give 2 you will get the second field in our case the second field is X you can see the output as X only. So, I think cut command is pretty clear to you. So, on the slide also you can see the hyphen D specified delimiter between fields default is tab. So, if you do not give anything it will consider it as a tab hyphen F specify the field number. So, suppose we will see some advance cut options. So, instead of only one field let us give many fields. So, let us give one first field now we want some other content suppose we want the date for example or 7. See I am not giving these numbers randomly it based on our requirement like first field is our root that is username. So, you count start counting from the first field. So, fifth field would be this would be second third fourth fifth fifth will be the again the username then seventh will be this path of the username. So, by providing cut hyphen D colon means separate these each field only we use with the colon separation then hyphen F force the field for first fifth and seventh hit enter. So, now you can see. So, these are the different fields which we got now. So, I think cut is very important and very useful throughout your unique session and we will see some advance use of cut commands later. Now, cut also allows you to choose the characters and bytes as we seen in the man cut. So, it shows that hyphen B is the option for select using the bytes. So, if you want to cut only certain characters say character number 1 to 4 that is first 4 characters you can use this command cut hyphen C 1 to 4 slash etc slash instead of slash etc slash password you can choose any file you want. So, I am not showing this command on the terminal this you can easily do it yourself. So, there are some commands like sensible default are assumed in such cases. So, this is important this you can see on the terminal. So, suppose cut hyphen C and up to 4 I will explain you shortly what is this slash etc slash password. This means we want characters up to 4 that is starting from 1 2 3 4 starting from 1 2 4 these characters we want. So, that is it. So, we are getting the first 4 characters of the file password. Suppose, we want characters from 10 onwards as you can see on your slide it is 10 onwards. So, suppose let us change it or say let us have from 6 onwards whatever characters in the file starting from 6th character to end of the file end of the line. So, you can see. So, after 6th character we are getting whatever left. So, what we have learnt is to how to get certain fields and certain characters from the file. Now definitely we want to process those things and we want to paste those things in certain other output files. So, this is an example. So, these example files are present in your model you can download as example test underscore examples there is an folder I have uploaded. So, there you will find all these files student dot txt marks dot txt you can download them and you can practice them. So, what it does I will show you an example. So, it joins the corresponding lines from two different files. Suppose, this is the command paste students dot txt and marks dot txt. So, first I will show you what is there in student dot txt and what is there in marks dot txt. So, let us see where we are by using pwd. So, we are in the desktop and ult. So, let us go to examples cd examples. So, we have here different sh files and different files. So, here you can see we have a student dot txt and marks dot txt. So, how to view those files you can view using cat command cat student dot txt. So, it contains name of the students like Hussein, Dilbert and and similarly you can view the content of marks dot txt. So, it contains the marks of different students. So, what our paste command is does to view the different option of paste commands let us try man paste. So, it will show you the different options of paste command that is again you can specify the delimiters serial help version you can explore this. So, coming back to a command our command is paste student dot student dot txt and marks dot txt fine. So, without using any external word editor or any any external graphical user tool we have just concatenated two different files into one file, but we have not written this output in a file that will show later that how to send this output that is Hussein and his marks Raoul and his marks all this to a file that we will see very shortly. So, but with the paste command you can combine the output of two files and you can make a new file. So, to do this in your graphical user interface you need some tools like you have to open either word pad or notepad then you have to copy paste manually. See there is an option in the man page of the paste command which has hyphen s. So, hyphen s will do it will print the content one below the another like now we have the output like Hussein has a name in the same line sorry Hussein's marks are in the same line suppose you want the marks to be printed in the below the names. So, you can use the command so that you can try your own. So, there is a small exercise you can do now. So, not now you can do it later. So, just read through this first column of marks file had a roll number how do you get a combined file with the same output as above try this and discuss it on modal forms now we come to the shell. So, this is a very important topic. So, output of cut hyphen d before coming to this command let me tell you what is piping and what is redirection is of course, this is in the next slide. So, you can just come to the slide number 38. So, the redirection tells you that whatever the standard output that means whatever terminal we are using that is a standard output. So, the standard output is redirected to some certain files file number which you give file name which you give. So, as you on the screen suppose you have the paste student dot txt marks dot txt gave you the combination of two files and now you are interested in this output you have already done the formatting and you want this in the some file. So, for that you need a redirection you want to redirect the terminal output to some certain file. So, that is what redirection means. So, for redirection you can use the greater than greater than symbol give the command and give the file name. So, this greater than will create a new file at specific location that location also you can specify. So, without previous command let us give paste student dot txt and marks dot txt use the arrow and create a file say result dot txt for example, we need a file result dot txt. So, it has created result dot txt. So, you want to see where it is just type ls to view the files. So, here it is you can see result dot txt previously not there it is now created and you want to see the content of result dot txt just cat it using cat command here it is. So, whatever was there on the terminal is redirected to a file this is very helpful coming back to the previous slide. So, here is an example. So, we have another file known as marks one dot txt let me show you the content of marks one dot txt for that just type cat marks one dot txt. So, this is the content of marks one dot txt. So, let me switch to the chat I think there is an important question how to separates in field fields in the file if delimiter is space just give space as a delimiter in double in double quotes just give the space as a delimiter default is tab. So, instead of call done you can give space that is in single quotes you can provide a space double quotes sorry coming back to the slides. So, this is an example with marks one dot txt you can see the content of marks one dot txt it contains four columns. So, what we can do is just try this example. So, let us try cut hyphen d. So, your question will be answered here give space as a delimiter because as you can recall in password file the delimiter was call done, but here the delimiter should be space because the fields that means the numbers are separated with space not call done. So, instead of call done we are giving a space now. So, use the cut command cut hyphen d give space which field we want suppose we want second field to end of the file say marks one dot txt. And on the slide you can see a backward slash. So, this means that there is a continuation after this command also means this is in complete a line from cut hyphen d to m underscore temp dot txt it is complete single command, but it is unable to fit in the slide. So, this slash gives the terminal an option to continue from there itself. So, after marks one dot txt it will come to the greater than symbol that is redirection. So, here we do not have any problem. So, no need to give that. So, now we can go to temp we can create any file. So, here temp we have created m underscore temp. So, again I create the same file m underscore temp dot txt. So, file is created. So, whatever so what this command do? So, it takes the delimiter as space delimiter as a space gives the field number two onwards two is the second field that is this one eighty nine onwards till end of the field because there is an hyphen after two. So, marks one dot txt. So, whatever the output comes so the expected output is eighty nine ninety two eighty eighty five ninety eight forty seven sixty seven. So, this should be there in the output file. So, how to view the output file just cat slash temp slash m underscore txt. So, this is the expected output. So, similarly you can practice the other commands. So, they are very similar to this. So, now we come to the piping. So, piping means we want the output of previous command as an input of second command. In many cases what happened? We want something to be gathered from the output of previous command which should be used in the next command. So, in many cases we will see like this example cut hyphen d space as a delimiter marks one dot txt that we are piping to paste. That means whatever the output this cut command gives that goes to the paste command and where it goes it goes to the second field. So, you can see there is an hyphen here. So, when we execute this command you can easily understand. So, you can So, let us see this command first cut hyphen d gives space as a delimiter. So, now use pipe to paste hyphen d space as a delimiter and student dot txt hyphen. So, as you know paste command takes two arguments. You have seen in the previous example where we have done paste command. We are using the paste command. We have concatenated two fields from each file. So, the first field will come from student dot txt and the second field will come from cut command because we are using a pipe. Pipe will provide terminal to get the output from cut command and redirect that output to the second field of paste command. So, you can see you got the output and now if you want to redirect this output to a file you can just use a greater than and give the file name. So, it will redirect to the next command. Coming back to redirection again similarly there are some standard inputs can be redirected like some suppose you have a command in a file and that command you want to use now. So, if the command is written in file you can again get it back by the less than symbol that is less than arrow and you can use that command. So, input and output redirection could be combined also. So, this you can try as an example or an exercise and try this at your place and please discuss on model forums. So, this is very simple nothing to be fair about. So, in our previous case what we did we just created a file like we just output the cut commands output to the paste command and now we want to output to be redirected to a file and from the same file we want that input also that can be done very easily and just see that file. So, this example shows the standard error. So, in Unix terminology we have different output numbers for different outputs like standard input sorry standard outputs is named as 1 greater than if you gives the 1 greater than symbol that means we want a standard output from the terminal. So, it redirects standard output. So, whenever we say standard output we say terminal output. So, you can see this is the standard output whatever you on the terminal it is a standard output. So, in many cases what we want we do not want the output of a certain command we want the complete output of the terminal suppose this is the complete output of the terminal ls. So, what we want we want this complete output of the terminal to be redirected in some file. So, instead of writing that we can directly write 1 greater than 1 greater than we will easily assume that it will assume that you want the output from standard output 2 greater than redirects the standard error. So, if some error is there in the output. So, it will redirect the error suppose instead of ls command I type l a or suppose l a s. So, it is an error ok. So, this error can be redirected to a certain file ok. So, how you will redirect just redirect using the 2 greater than command to a file. So, it will redirect to a error file. So, this you can try also as an example yeah please if you please ask us any doubt if you have. We have a question from Saint Joseph Kerala. Can you please give some more examples regarding standard output and standard errors. Standard errors this standard error is not a priority yeah. We will certainly need to know standard input and standard output ok. So, let us yeah we will see some more examples yeah. Thank you for your question we will see that we will just see what other questions are there ok. Thank you any other question did you have. Basically what is the difference between redirection and piping. Ah ok that also we will see in more detail yeah ok. Any other question did you have. No sir. Ok ok sure ok. Let us now see a question in Don Bosco, Guwahati please ask. Yes sir going back to the slide number 41 in the piping part. Yeah. So, at the last of the command here we have typed a hyphen. So, what is the use of a hyphen? Hyphen yeah. So, after students.txt there is a hyphen there. Yeah. If I do not give the hyphen I do not get the output. Yeah yeah hyphen role of hyphen is a little difficult topic we will see in more detail yeah. Thank you for your question. We are now connected to VP College of Engineering Baramati please ask. So, my question is while using this space space command. Hello. Yeah. Yeah. While using this space command. So, in one of the file marks are there and with the role numbers in one of the file their names are there. Then I want I want role number first then name of the student and then remaining contents that is marks. So, what I can do for this. You want to interchange the sequence of the columns. Yeah yeah same thing that I want to do. Ok ok sure we will see that we will see that yeah. Now we are connected to Shastra University, Tanjavur yeah please ask your question now. So, will the cut command work only in the current directory will it not work in other directory. Cut, cut command. No cut command will work for files in any directory. The file name has to be specified with the full directory path if that file is not in the current directory yeah, but it will take files from any directory. So, there are some questions on chat. Yeah. Yeah. So, whether the cut command will work in the current directory or any other directory also. So, that we will see on the computer yeah. So, let me just quickly recap the questions. One of the questions was we want to see more examples of standard input and standard output. Then we want to see the exact difference between pipe and redirect. Then we want to also come to the question about where the document was created in certain directory. That we will see now and exactly the role of hyphen in the usage of paste and how to use paste for interchanging the sequence of commands, sequence of columns inside a file yeah. So, let us go back to this. So, we have students dot text yeah this is a list of names of students. We have some big file marks yeah. So, let us look at this marks. Let us also see what other file we have yeah. This has only three columns. So, let us quickly put some more names into this. Suppose these are the names of the various people yeah. So, cat marks yeah. So, now the first question is how do we use the cut okay. Now cat marks dot text suppose this marks dot text is being catted it is being shown on the screen yeah. Instead of it being shown on the screen we want it to be used by another command yeah. We want the output of the cat command instead of going it going on the standard output. What is the standard output? Standard output is always the screen, standard input is always the keyboard yeah. Standard input means what there are certain commands that require you to type something. For example, the editor. You once you open an editor command then you are supposed to start typing in things into the editor using the keyboard. So, standard input will always be the keyboard. Now whenever you want to see the output of some command the output will come where default it will be standard output yeah. So, standard output means s t d o u t the standard output is always the screen that is a cat command cat marks dot t x t has shown the output to the screen. Now we want the output to get utilized by another command yeah. We want it to get utilized as a file for another command that takes its arguments as files that is the pipe command yeah. So, now cat marks dot t x t is what we can pipe through a pipe we send to another command. So, can you now suggest a example of a command that takes a file name as its argument yeah. For example, l s yeah l s minus l of a file name will so no l s l s takes l s will sorry not l s yeah that is that is my friend Prasan theory suggesting that we can do l s instead of catting this yeah sure. For example, look at l s minus l s minus l yeah let me make the screen slightly smaller l s minus l l s minus l has spitted some output on to the screen yeah it has spat some output on the screen. Now from this we want to extract out some information what information do we want to extract out we want to get only grep grep has not been taught. See there have been some questions about asking for examples of standard input standard output pipe redirect. So, even these examples it is hard to think of examples from what has been taught to you so far yeah. If we can think of any examples that is not difficult, but if we are asked to think of examples to depend only on what has been taught to you so far that is making things a little difficult I hope you will acknowledge this as well as teachers at various if you are asked to give examples of things we only from the things we have taught that is a little harder. So, now since grep is one thing we will anyway teach you why do not we quickly see grep yeah. So, what does this grep do? So, let me just tell the very simple usage of grep yeah. So, there is this cat marks dot txt in what am I teaching now in order to understand pipe redirect and all those cut paste related things we are now first going to learn grep grep anyway we are planning to learn. So, we will do it now only. So, cat marks dot txt has 1 2 3 4 5 5 lines now we want to suppose see which line has some very specific pattern yeah. So, grep is a command to look for pattern in file how does grep work it looks for a certain pattern inside a file this is how you will use you will type the pattern and then you will find you will type the file name inside which you want to look for this pattern then it will spit out all the lines which have that pattern suppose now we are looking for name 3 pattern inside which file inside marks file yeah. So, this now has looked for the name 3 pattern inside the marks dot txt file and it has shown on the standard output only that particular line which has that pattern name 3 yeah. So, usage of grep is that clear? So, grep pattern let me repeat file name yeah this how one is of course if I press enter it will say that file name file is not there yeah this is just an example grep name let us say name 2 and marks dot txt was the file we are looking for yeah. So, it has given us only that particular line which has this pattern called name 2 of course it does not have to be only names it could also be let us look at whole has 47 any line that has 47 as a pattern it will get shown it does not have to be a whole word you can look for only the character 7 yeah and recent Linux versions recent meaning since several years will also show that particular pattern that has been found in a different color very helpful for us this is how grep works grep pattern file name. So, how what does grep do grep command takes a pattern of course pattern has to be given otherwise what will it search for file of course file has to be given there are no options here yeah now what we can also do. So, what my friend Prashant was telling us to L s minus L now this is why we wanted a smaller L s minus L has shown all this information now from this perhaps we are interested in looking at which all lines have character 18 yeah there is this character called 18 we are looking for only those lines which have 18 character somewhere in that line. So, line by line it will search for that pattern and it will spit out on the screen yeah what will get spit out from the output that has come out we want to extract out only those lines which have the character 18. So, what output do we expect we expect this line we expect this line also we expect the last two lines also yeah why do not we choose another character where we expect only 1 2 1 2 yeah look at this if you put 7 7 4 4 then we expect only the last line to come as an output yeah. So, why do not we try that. So, L s minus L instead of that output coming on the screen we will send it through pipe we will kind of filter it yeah we will give the output of L s minus L which would default it would have come on the standard output we will pipe it through to which command called grep and now grep of course has to be told what pattern to find does it have to be told to look for 7 7 4 4 pattern inside which file does it have to be told that no why because that particular file is being piped through yeah. So, now what grep has done grep is not going to take an output file it will not take a file name as its argument why because that is being piped the information that it is supposed to look through in from a file is being provided to it through a pipe that is how we will use the word pipe. Pipe means what somebody wants to eat food instead of giving food into the mouth we will send a big pipe and send the information from end of other end of the pipe and directly send the information into the mouth through the pipe I think that is how the word pipe is used yeah somebody let me repeat this extremely important usage of pipe as soon as you use pipe this I should say in Linux and Unix this is the best thing in Linux yeah the pipe is the best invention whoever thought of it would have certainly have you would have had the gates of heaven open for him yeah all others who could not think of pipe cannot go in. So, let me repeat L s minus L is some output that default goes to the standard output yeah, but instead of it going to the standard output we want it to get utilized. Utilized now as a file as a file that is an argument for another command yeah which command for example we are doing grep. Now grep how does grep work grep takes a pattern and it requires a file it requires only one file please note there is no hyphen we are using here because only one file has to be specified to grep yeah the default for the default for the default grep to work only one file is required that is compulsory there is no option. So, grep instead of now specifying the file that information which it is supposed to take from the file is now being provided through pipe. So, when you do this that output is sent through a pipe for the grep command yeah this is as well as pipe is concerned this is different from redirect why what where is redirect now. So, this you might have you might not even have decided what all to do yeah this L s there might be some really big difficult program that is generating lot of output which you do not want to generate again you want to save the output from the screen into some file yeah if you want to do that then you can redirect it to a file file output instead of standard output S T O U T sorry let me make the font larger. So, L s minus L if you are not typed anything after that it would have come on the screen instead of it coming on the screen we have put a greater than sign greater than sign means like arrow redirect it will go and get copied onto this file what file we have to choose the name now yeah you cannot you cannot skip this part file name has to be typed. So, one file has got created and nothing has come to the standard output now why do not we see what is there in the file how to how to see that just do cat yeah. So, what is come here is exactly the output that would have come if you are not redirected it. So, this is the output yeah it has got redirected into the file notice that the file also has got created already yeah while you are doing L s minus L as soon as you gave the pipe into that that file also has got listed surprising you are you are creating that file to redirected and the file is already got created that is how Linux works some small technicality do not need to worry about it now. So, this explains very clearly the difference between pipe and redirect now what about standard input what if some particular file requires some input and that you wanted to come from a from a file that is when you will use the less than sign yeah. So, when you start typing an email for example, and then as soon as you open the emailer inside the terminal then you are supposed to start typing the message that message if you wanted to come from a file then you will use the other symbol less than we saw pipe greater than less than yeah pipe is just for sending the output is from standard output into a to another command yeah that is different from sending the output to a file for sending output to a file you will use the redirect command. So, standard output going to a file use redirect which means greater than sign. So, what we have not yet discussed is the hyphen. So, what is hyphen now? So, now let us see yeah. So, let us see cat marks dot txt yeah now let us cut with minus with the delimiter space yeah and first column yeah how do you say minus f minus f minus f 1 oh sorry I have to I have to specify the file name cut yeah this is perhaps the mistake that was done in a particular person who explained about the document I forgot to type the space and I was corrected here that the space is required yeah, but at the end of this finally, we have to specify the file yeah what does this cut do cut cut and remove only a specific column from a file yeah that much is required you cannot you cannot skip that part file has to be specified if you do not want the default delimiter of course, you can do minus d as an option and specify different delimiter yeah, but the file itself has to be specified let us specify marks 1 dot text again. So, now what this has done it marks 1 dot txt sorry has all these different different columns we want only the first column how did we specify first column we specified by minus f 1 yeah and then the file name itself. So, cut is the command that takes only one input now we might want that this first column comes to the last yeah that is one of the question that how do you use space to interchange the columns that is one thing we will see now, but then in any case what perhaps one particular person had forgotten was that file itself has to be specified to cut yeah cut has to be told that it has to remove and give only the first output first column to the standard output, but from which file to take that has to be specified you can also specify not just first column first and third column let us say yeah this will see notice let me type this again this was the original file from which we are showing only the first and third columns. Now, we might want that suppose we want only we there is a possibility that we want only the names yeah and we know that names is the last column last column in this case fourth column sorry sorry we wrote a new one. So, suppose we are doing so the fourth column has only the names of this particular file which file must not text and it gives only the fourth one so there is one way of removing only the names and from this suppose we want only one particular name yeah so we might redirect this to grep name four may be this names have actually name first name surname and we are looking for the full name of a person only the surname we know yeah so that is an example where we might require to do this. So, then grep four grep only the pattern four yeah please note that we are specifying only the pattern here it could occur anywhere inside that line so it has given only name e four. So, let us consider the problem of taking marks dot text taking the last column and putting it as the first column first column also. So, how do how would we do that one way to do this is I hope the problem is clear yeah we have fished out all the names and we can redirect this to a file called just names yeah. So, what is this file newly created file has just the names now we might we might say I do not know let us go back to that marks one dot t extend put the names back paste minus d put the minus paste minus d put the delimiter space then marks. So, please note the mark paste command needs two arguments two file names yeah so paste marks one dot txt and just names if you do that it will show the output on the screen yeah now what did we do from marks dot txt we extracted out the names that we copied to a file called just names and then we pasted file one file two now did is was it really required that this intermediate file you create only for this purpose. So, why do not we remove this redirect and now you spaced yeah and now what is the first file now you see paste requires two files it compulsorily requires two files of which only one is being provided by the pipe yeah now first of all you have to specify another file second if there are two files you have to specify one is coming through the pipe already. So, the one that is coming through the pipe is the first file or second file now yeah very clearly if you interchange the sequence of files the pasting will also interchange the pasting will happen either earlier or later depending on the sequence of files you specify as arguments to the paste command. Now, your specific file one file two yeah among these two let me increases font size so, this paste requires two output file two files as arguments of which one of them is coming through the pipe which one is coming through the pipe that one is where you will put the hyphen and the other one you will genuinely specify the exact marks one dot txt yeah if you do this then it will do that is when that just names role is not required now that is being provide through the pipe yeah. So, let me repeat if you are using after the pipe a particular argument that compulsorily requires two file names as arguments then when you are sending some one of the file information through pipe you have to specify whether this particular information should be taken as a first file argument or second yeah if this information is not provided then paste will not know it will not know whether the output that is coming through the pipe is it the first file or second file there is genuinely a big ambiguity if you if that hyphen were not provided yeah. So, notice now that we can also put the hyphen here now it will hyphen the whatever is coming through the pipe is playing the role of the first file. So, this is how it is so, after we have understood the role of the hyphen now we are in a position to thank you now we are in a position to learn how to interchange the columns in a in a file yeah. So, how do we do that so, let us suppose the problem is that let us get marks dot yeah so, this is marks dot txt file and now we are interested in we do not like the names to be in the last column we want the names to be in the first column. So, if you want the names to be in the first column we are going to cut the last column and then paste well I think use two pipes I am not sure if that is possible so, let us do like this yeah if you do this then here it has taken the last column and also put it as a first column yeah. Now, the next question is you can get rid of a particular column yeah this is also something you can do easily how you just pipe it again you cut minus d again the delimiter space now you want which only the first, second, third and fourth yeah. This way now we have just got rid of the fifth one of course what we can also do is we can use dash for all the column from first to up to fourth yeah. So, somebody's question about how to interchange I have not really directly taught how to interchange what I have told is whatever you want to remove just cut and remove it and you paste it to whatever position you want after you have pasted it to whatever position you want you again pipe the output to cut command and remove one that you have duplicated yeah. Does this answer the question about how to interchange the columns perhaps paste can be used paste can be used with multiple file names also more than two also two are at least two are required if there are three or four then that will also allow you to put information in not just interchange columns, but have more flexibility in rearranging the columns. So, this answers most of the doubts this answer is the difference between pipe and redirect the information comes from standard input for that we require to see another command that time we will see this I use the example of I only use the example of e-mailer man paste and man cut is the ideal thing because cut and paste have capabilities much more than what we are covering now. Let us go back to the slides now we have seen pipe. So, as I said that we took an example where we created a intermediate file that intermediate file anyway has to be removed eventually that is when this pipe is going to play a very useful role tab completion I have already explained. So, it is strongly recommend that you use tab to autocomplete that ensures that no typos occur in the typing of names etcetera only in case of an ambiguity you have to resolve by typing a few extra characters. So, bash provides tab completion not just for file names and directory names, but also for commands themselves also for host names, variable names, variable names we are yet to cover the only variable we saw was dollar home, but there are many more variables which we will see in more detail today history. So, you would have seen you would have noticed that I was using the up arrow mark key for navigating through past commands. So, but then if the command that you typed was very much far in the past then you would have to use up arrow mark key again and again is there is you have to you can just search through all the typed commands all the commands in the bash history. So, for example, I had used a command called v i. So, I can do control r v i as well as the press v it looks for all the past commands with the v character anywhere in that command not necessarily the first one then you can make it more and more defined by typing more after we see whether it has found the command that we are looking for or not. So, we only saw that we do not want a space in the name of a file or the name of a directory why because the space is very crucial for separating command from argument command from option one argument from another argument. So, we have some more such characters which we do not allow these are all called meta characters. We already saw pipe is a meta character pipe has a very important means slash itself separates directories from sub from its sub directories exclamation mark also has some important role quote single quote single open quote single close quote both have really different meanings double quote of course there is only one semicolon these are all what we will call meta characters very important meta character is a star star means everything all possible completions all possible characters that can remain here except empty character. So, the star should be at least one character. So, we will go back to this and see an example let us see LS. So, there are so many files there are some txt files some dot sh files. So, now let us see only the txt files LS star dot txt will show us all those names where star had at least one character. So, whatever just names this is just LS just underscore names does not have dot txt anywhere that is why just names did not figure out in LS star dot txt. So, the star can be used inside something also for example, you might say LS m star x t. So, it says marks one dot txt and marks dot txt are the only two, but please note star cannot be the empty character. Now, let us go back to the slides another important command is sort sort is to sort the output. So, you can use sort again sort is a command that takes a file name as an argument you can use sort file and the output of sort will just default come to the screen which is the standard output instead of taking its input from a file you can get sort to take its input from a pipe. If a command is taking its input from a file only then you can use pipe to give the input to that to that command. If the input is required to come from the keyboard that is when you will use the less than sign which was the opposite of redirect. So, sort is a command that you can see in more detail it will just sort you might also choose to say sort numerically sort based on numerical value especially for file sizes we might want to sort not just based on the location of the character we might also want to sort based on the fourth fifth sixth column based on a particular field. So, please see help sort minus h to see more advanced options minus case specific which field to use for the sorting purpose and for numerical value based sorting are also for reversing the sort of course the output if we do not want it to come on the standard output you can make the output to go to a file using the redirect symbol. Crap I have already explained because we needed to see in more detail hyphen and pipe. So, what is this slash has the slash been explained? So, when we are typing a command on the on the prompt then it is possible that you run out of space and you want to still type that is when you will use the slash and then when you use the slash then the batch script then the batch shell knows that you are yet to type more and then it will wait for you to type in the next line and you do this and then at the end of this when you press enter it will execute them all together. So, hyphen we have already seen grep we have seen. So, grep is case sensitive by default if you want grep to search for the pattern by ignoring the case then please use minus i very important while using grep is to invert the search. Instead of only showing those lines this is what we saw the default grep shows the lines where it found that pattern, but you might want to show all other lines except those lines which have that pattern in other words to reverse the search to invert the search. So, we for inverting the search tr is an extremely useful command that is that is for translating tr for translating certain characters to certain other characters. For example, when we transfer files from windows to linux in windows it turns out that file names are case insensitive. So, whether the same file is written in capital or small windows will not make a distinction, but in linux they are separate files. So, if you have written a script in which you expect that the file names are all in small, but you copy all these files from windows to linux that is when you will see suddenly the script is not working because it is looking for small case letter file names and all these files are actually having capitals. That is when you might very crucially require to rename plenty of files into new files all capital to small or may be small to capital tr is extremely useful in that case. So, tr is one example of what reads from the standard input writes on to the standard output. So, there are some more advanced things for tr if we require it only then we will see it again the rest of today's and tomorrow's session does not require tr unique. Unique if you put the UE words there then unique just means that if there are multiple occurrences of something then it will give a unique one. So, unique just removes duplicates removes multiple occurrences only if they occur next to each other. Please note that if there are two lines that are repeated in a file, but if those two lines are not next to each other then unique will not remove one of them. Unique will remove only next to each other only consecutive duplicated lines. You might also want to see only the ones that are duplicated or only the ones that are not duplicated. These options are also possible with unique. As I said that if you are concerned that unique should also remove lines that are duplicated but which are not consecutive. So, if you want unique to remove duplications even when they are not consecutive lines that is when we can prefer we can choose to first sort those lines and once you have sorted then these duplications even if they are not next to each other they will always come together once you use the sort command and you can out you can pipe the output of the sort to the unique command. That way duplications will be removed even if they are occurring separately if they are not occurring consecutively in the items dot text file. Now, we have come to a very important stage called shell scripts. Till now what we had been doing is we are just typing the commands onto the screen onto the prompt and we are executing them seeing the output output was being shown on the screen. If it was not required to be on the screen we were again executing this and redirecting it to a file. But then the purpose of as I said the purpose of the prompt the purpose of the shell is when you want to automate various things when you want to repeatedly do when you want to repeatedly do something that is when you consider it very useful to type all these commands into one file and then just execute that file. If you expect that whenever somebody gives you the marks of all the students the same set of operations have to be done again that name has to be shifted from the last column to the first column. If this has to be done if this has to be done repeatedly each time are we going to write the same command? No, what we will do? We will write all these repeatedly occurring commands into one file save it and keep and then just execute that file again again. This is where we require how to script how to write a shell script. So, all the commands that we need to execute we will write into a file using an editor. This is where we require to know what editor to use. So, we have just begun seeing the nano editor. So, let us take an example. So, these are the commands that we can choose to type on the screen. Instead of typing on the on the screen meaning on the prompt instead of typing on the prompt we can write all this into one file called test.sh. Let us see what file name has been recommended for this example. I would recommend that you go through the slides carefully write them onto the same file. Save the script as results.sh results.sh because this is a bash shell script. The extension has been recommended extension is .sh. Let me tell you let me repeat the extension is only a very good convention bash will still work even if it is not .sh file you can still execute it for the same performance. So, when you are writing a bash script is very useful very important very important to tell that this is a bash script. Why? Because that information is not necessarily contained in the extension. So, the first line is always hash exclamation mark bin hash with these slashes. So, this tells that whatever comes after this is a bash script. Let us see this let us see an example. Here we have 55.sh. So, some there is one command long list of commands one piped into an output of one piped to another all written in a bash script. So, let us see file 55 to .sh. 55 corresponds to the slide number here that is why luckily the correct one. So, it says this bash b b stands for born a for again. There was first one sh just a shell then this is how Linux has evolved Linux and Unix both have bash shell. So, born shell was the name that was improved to born again that that is a full form of bash. There was the first shell was just a sh just shell. Now, if we move this 55.sh to not not move let us copy it test.sh.pdf. Now, let us see file test.pdf. It still says it is not a pdf file it is still saying that this is a born again shell script executable. Now, let us try to change its mode. How do we change the mode? We will remove the execute permission and again check. It is still continuous to executable. Now, what we will do? We will see this test.nano. So, now we will just remove this. I should tell you why I am doing this in so much detail because hash is also write function. Unfortunately, I have by changing the mode I have given only read permission to myself. I have forgotten to give read and write permission to myself because of that it is not allowing me to save this. So, why do not we change mode and give 6 0 0 to this file? Now, you can do you can try this yourself by just by just 4 0 0 it gives only read permission. This is the part we had skipped, but then now there is read and write permission both to only the owner that is to this user that is me. Now, it will allow us to make whatever changes we want. Now, we will save this it has allowed us to save now. Now, when we do file test.pdf this script no longer knows that this is supposed to be a batch script. So, notice that we have removed the first line and suddenly the file command considers this file to have only ASCII text. It no longer knows that this is a batch script. What you can do after today's lecture? Check by executing give the execute permission to this file. Right now, it has only read and write permission does not have the execute permission. Learn how to give execute permission, give execute permission remove the first line in any case the line that we just now removed and still try executing it. Perhaps it executes and does the same job whether you have the first line or not it performs and executes and performs the same job. In that sense in that case what is the significance of that first line the hash this is something we can discuss at a later point after you have tried this. This other question on chat is about after copying using paste and redirection how will we save the file? So, when you do the greater than sign it already creates a file with that output instead of the output going to the standard output the output has gone and into that file the file has already got created that is the answer to this particular question about after copying using paste and redirection how we will save the file. The file has already got created instead of the output coming on the screen on to the standard output it has got redirected to the file to the file name that is specified. So, we will stop now please have your lunch we will meet immediately after lunch. Thank you very much.