Hello the beautiful people.
And welcome back.
I left you with a bit of a cliffhanger in the last video where you learned all about the basics of piping.
Now, in this video, we're going to take what you learned about the basics in the previous video.
And in this video, we're going to level it up and teach you some advanced piping techniques.
So with the basic stuff you learned last in the last video about just taking the output of one command
and piping it directly into the input, into the standard input of another, that doesn't leave much
room for flexibility, whereas there's loads of really cool things that you can do with your pipelines
if you learn just a few more techniques.
So in this video, we're going to go over those advanced piping techniques and by the end, you know
how to make advanced pipelines using the T and X args commands.
So let's go ahead and jump into it.
All right.
So let's just have a quick recap of what we did in the last video.
So in the last video, we use the data command to get loads of system information about our computers
clock.
And what we did was we passed that data into the cut command because we just wanted to cut out the day
of the week, which is a monday.
Now to cut out the day of the week, we have to say that this data is actually broken up into several
columns and each column is separated by a space.
Now, another way of saying that is that each column is delimited by a space as a fancy word in computer
lingo.
And so what we did is we gave the the cut command a delimiter, and we said the delimiter is a space.
And now once we've said, okay, each column is split up by bi spaces, which field do we want?
Which column do we want?
What is the first column now?
Fields in the command are called sorry, what columns in the command are called Fields.
So we just said fields equals one.
And when we press enter, that cuts out Monday.
So that's what we did in the last video.
Then I gave you a little bit of a challenge.
I said, Hey, how can we go about actually saving this information into a file but at the same time
also pass it down into the pipeline?
So how can we save it into a file, but also pass it down into the cut command so that it can be operated
on so we can get Monday out.
So we're trying to do two things at once.
So to do that, we actually need to have another command called the T command.
So let's take a look at how the PT command works.
So here's an image of how the T command works.
Now I'll put a link to the original picture in the video resources, but you can see here that we have
a pipe between two commands.
So here's a command over on the left and we have another command over here on the right.
And in the middle we're using the PT command.
Now, we haven't covered what these specific commands do.
It doesn't actually matter so much.
What I want you to focus on is the PT command in the middle and just understand that we're trying to
pipe two commands together now, just like a t junction in a pipe of water, we can use the PT command
to cause our data to flow into directions.
We can cause it to flow horizontally as well as flow vertically downwards into other files.
You can imagine it working like that.
So this, the PT command allows us to pass the data on to the rest of the pipe, but it also allows
us to keep it in a file.
So you can see here that we've got a command on the left that is trying to pipe its data across into
another command on the right.
In the middle, though, we pipe it through the PT command and the PT command, we give it a command
line argument of file txt that could be any file name that you want.
And what happens is the data does pass all the way through from the standard output of one command to
the standard input or the other.
But it also falls down.
You can imagine it falling down from your command line into a file called file that txt or whatever
file name you gave the PT command.
So that's how the PT command works.
In theory, this is how this graphic works.
Let's go ahead and see it work in practice.
Okay.
So now that you understand how the PT command works, let's just have a quick refresher of our command
pipeline.
We have the date command, which gives us a whole bunch of information about our systems clock.
And we wanted to cut out the Monday or whatever day of the week it actually is.
So we take the date command and we piped it into the cut command.
Now we notice that the data is broken up into columns that are separated by spaces.
So we say, Hey, cut command, we have a delimiter.
That's a space.
The data is delimited by spaces and we want the first column or as the command calls it, the first
field.
And that gives us the day of the week, which in this case is Monday.
Now, the challenge was we want to not only have that come out, we also want to save the entire date
into a file called called full date txt.
So here's how we would do that.
I'm going to press the up arrow key to get where we got before.
Now what I'm going to do is I'm just going to squeeze in here the t command.
Okay?
Now the t command is going to put one of those like T junctions in our pipeline.
You need to imagine it in your head.
Okay.
So what's going to happen is the data is going to pass all the way through the pipeline horizontally.
So it's going to pass from the date command standard output and go into the standard input of the cut
command.
So it's going to flow straight the way through.
But now what the T command is going to do is it's going to allow us to save the data vertically downwards.
So you can imagine it being like a big letter T, like a big T junction.
The data is going to go downwards into the file called full date dot txt.
So here we are.
The data is going to go horizontally down.
Oops.
I've opened a new term for my bad that is going to go horizontally across.
Okay.
And it's also going to go vertically downwards into a file called full data txt.
So when we do that, we see that the output of the day of the week has still happened because that was
passed through the cut command of the cut command, spit it out to its standard output, which is still
connected to our terminal.
But when we open up our file explorer, we can see that now we have a file called Full Data.
TXT I deleted all of the other ones we had before, so we were starting afresh and now we have full
data.
TXT now when I open that well hey we can actually see that all of the data data has been indeed saved
in a file called full date dot txt.
Isn't that awesome?
That's proper.
Cool.
Right.
So what happened was the date command spat out all of its information all the way across the pipeline.
And when it got to the T command, the T commanders took a snapshot of the data in the pipeline and
passed it down into a file called full date txt.
So that file contains all of the data that's coming out of the date command.
But then the data was passed on into the cut command which did some processing and that spat out the
day of the week, which in this case was Monday.
Now, I've got a quick challenge for you.
Okay?
And I think you can do it.
What I want you to do is I want you to instead of having the the day of the week spit out to the terminal,
I want you to see if you can figure out how you can use redirection to actually cause that data to be
saved in a file called today dot txt.
Okay.
So instead of having the day of the week spee spat it to the shirt, spat out to the terminal.
I want you to have it saved in a file called today.
TXT but also you still need to have the PT command in here.
So I want you to press the upper arrow key to get what you've got before and now do the redirection.
So I'm going to pull the video now and then come back and see how you did.
How did you manage it?
Did you do it?
Well, this is how you this is how I'd go about it, right?
So I would just right at the end here, because here's where the data is actually coming out from.
I would just have a redirection from standard output into a file called today dot txt.
And it's literally just that simple.
So once we've done that, if I go ahead and press enter, we can see that when we open up our file commander
here.
We've now also got a file called today dot txt and inside there it has saved the data the day of the
week, which in this case was Monday.
Let me delete both files to so we can see this in all of its glory.
We've got no files.
I'm going to press the up arrow key press enter.
And when we take a look ha ha.
We've actually managed to save all the data into full data.
TXT And we've also managed to save just what we wanted using redirection into today.
TXT isn't that awesome?
Right.
That's kind of that's that's really awesome.
I think so.
Anyway, so what we've got here is the T command basically takes a snapshot of the data that's flowing
through the pipe at that point and saves it in a file that, that you give it and then redirection will
also do the same.
But once you've redirected standard output, you can no longer pass it down the pipe.
So that's why we use the PT command.
The T command allows standard output to continue flowing down the pipe, but also allows you to effectively
redirect it to a file and take a snapshot so that it's saved there.
So another way of saying that is that once you've done redirection, you can't do any more piping.
So once you've redirected standard output like we have here in the today txt, we can no longer do any
more piping down down the pipeline.
It's going to maximize the terminal.
We can once we've done this redirection to today, that's the end of our piping days.
But what we could do if we wanted to save all the data into the txt but continue the pipeline, then
what?
Then that's when the t command would come in.
So we do for example today txt in the T command and now we can continue to pipe.
Okay.
So just again, if you do redirection of standard output, that means no more piping.
If you want to take a snapshot, but continue piping, that's when you use the T command.
And now I could continue piping on down.
Okay.
So I wanted to also cover the x args command in this video, but I think we're pushing it for time here.
I hope that that has made it clear what the T command is.
In final summary here, for the T command, the T command allows you to save a snapshot of the data
and continue doing your piping, whereas just using redirection will save a snapshot of the data.
But you can no longer do any piping.
So if you want to keep building your pipeline but keep a snapshot of the data, use the T command instead.
So in the next video, what we're going to do is we're going to have a look at the x args command,
which is a really powerful command that allows you to turn your your pipe data into command line arguments.
Ooh.
Okay.
So let's go ahead and I'll see you there in the next video.