[No audio]
Next topic we have is combining and splitting files.
You could combine multiple files into one
and you could combine one file, you
could split one file into multiple files.
Like just an example right here.
When you cated three files, you could output
of all those files into a fourth file,
which is you call it file4.
So what will happen is whatever is inside, whatever the
contents of those files, one, two, three, they will be
combined and they will be pushed out toward file4.
So that's how you combine it.
So how do you split it and why do we need to split it?
Okay, well, there are certain times when you do have big,
huge files and you do need to either compress it.
If the compressing is not an option, then what
you could do is you could split it.
Meaning you chop that file into different files.
And the reason you do that is because sometimes you have
to send files across one computer to another or to a
third party vendor, or if it's a log file that they
have to check, they have to check and it's huge.
And it's huge.
So the only way to do, and your
only friend is out there is the split.
So you split it, chop it, whichever the number of files
that you want to do and boom, you will have it.
So let's look at this file that we
have and we will create some files.
And in this example, you see I have a file
and I'm splitting the file in 300 lines per file
and putting it into a file called childfile.
Let's look at our Linux machine and I
will explain it to you much better while
we are doing it through the command line.
[No audio]
Okay, this is our Linux terminal, which
you guys are very familiar with.
Okay, we are in our home directory, just confirmed that.
So we don't have to put all the practice files
or the stuffs that are not belong to other directories.
So we know we are in the right directory.
Now I want you to create a file,
let's call it,
[No audio]
countries, or you know continents.
[No audio]
Let's call it countries That's fine.
[Author typing]
The file is created and I am using vi
So the first line I'm going to create is England.
This is just a country.
Second one is USA, third one is Canada and so on.
But if you don't know how to use VI at
this point, you will be learning VI later on.
But if you don't know how to use VI at
this point so what you could do is echo.
Let's remove the countries file, then do echo, put
usa into countries, cat it and you will see.
Yes, it's there.
Next one you put an echo uk and
you output with two redirects, to
[No audio]
countries. Make sure it's there.
Yes, we have two countries.
We will keep doing that until we have some text in it.
So uk, uae,
[No audio]
and canada and
[No audio]
and
[Author typing]
france, and
[Author typing]
switzerland, and we'll stop here, japan.
So just do that,
confirm, that you have all those contents in there.
So right now, how many lines do we have?
We'll do,
we have 7.
So I'm going to make, split them, into split,
and just check the option is -l,
I'm going to split two lines each of countries, and
I'm gonna put them in a file called separate,
just sep,
and I'm going to hit enter.
Now let's see what we have.
So you see, automatically Linux knows that once
I'm going to create file sep, of course
I requested to create two in each file,
it has automatically appended with names like a, a, a, ab, ac, ad.
So let's look at what's in our aa file.
We have usa and uk, bb
[No audio]
sorry ab,
[No audio]
uae and canada,
ac france and switzerland,
and the last one is japan.
Okay, so every file has two entries.
Why we don't have two entries in the last file?
Think about it. I'm going to give you a couple of seconds.
[No audio]
Okay, I hope you guessed it right because, we do not have,if you go
to countries file, we do not have the exact numbers.
Meaning we do not have eight lines.
So that's why it took the first two put it in
one, first two second file, first two third file, and since
we didn't have anyone, japan was the only one left alone,
sorry, japan,
and that's why it went just into one line to that file.
That's how combining file and splitting files work.
This is a helpful tool when you have
to split large, long, huge files, and you
have to transfer from one computer to another.
[No audio]