[Autogenerated] Now, as we've just introduced,
we can take a look at how we can process simple text files and we have to
understand about the I F S or our internal field separator.
It defaults to being any white space character.
So that could be a space, a tab or even a new line.
If we go through and create ourselves a very simple text file.
Here,
we've got three fields that are being sent through to a
single line in the employees dot text file.
We can create this from new and we've got Fred the age of 23 the department,
we can append to our existing file and add in HANA
who's 22 works in the I T department.
So we've got two lines each with three fields.
We can write a bash script, but we can also write the script at the command line.
So using the wire operator, we can read in the name variable,
the age variable and the department variable,
we go into our iteration using the do keyword and then we
can print out what our current name is.
Our current age is and our current department,
then we're going to read in the next line.
So we can process each line populating the variables
through the iteration once we finished, we use done.
But of course, we got to specify which file we're reading from.
Now, this then shows using the default I F S.
But very often when we're working with data files,
that could well be commerce separated CS V files.
Now we can easily change then our space separated files,
employee dot tech to a CS V file and we can use the T R command.
So we're translating a space through to a comma.
And there is actually a space between those first two quotation marks.
So we're quoting the space, we want to translate a space to be a comma.
We can then set up a variable to hold our current internal field separator
and then set our internal field separator to be the comma.
Then we run through the same process as we did before.
It's exactly the same now, except of course,
we're reading in from the CS V file.
We can return our internal field separator to the old value by
reading in the variable that we initially set.
Now as well as these files that we have created.
We have many files in Linux such as the E T C pass W D
file that use a colon as a separator.
So we can begin the same way storing our current field
separator into the old I F S variable.
We use our, our input file separator to be a colon.
We're going to be reading in from our E T C password file.
So this has seven fields.
So we've got seven variables for ease.
I've just given them a single character.
So we've got the name, the password, the user id,
the group ID D, the comment, the home directory and the default shell.
So we're just storing the seven fields into variables that have got
a single character name as we're printing out.
Now, we can use echo minus E.
This allows me to embed special characters.
So I can then go through and use user and dollar end to display the user name.
We can then do a new line slash end and tab in.
So we've got everything indented underneath our user name.
We've got then our password, we do a new line and a tab,
our user id, a new line and a tab, our group ID D,
a new line and a tab.
Our comment, a new line and a tab.
We have our home directory, a new line and a tab.
And then we have our default shell.
So it's a little bit longer and we got to be
careful with the new lines and tabs, make sure we have them in the right places.
But then again, we can go through and end our iteration.
We're printing again one line at a time.
But reading those lines this time from the E T C and past W D file and we
can get a relatively nice report being laid out for us.
Once we've finished, we can return our I F S back to what it was.
So changing back from the colon through to the space.
Now, of course, all of this is good looking at it on the slides,
but you really want to see the results.
So why don't we move out to the command lines?
so we can start learning some of this.