[Autogenerated] Hello and a really big warm welcome
to this plural site presentation.
A module where we're going to take a look at how we filter
data from differing text file format.
My name is andrew Mallet and I'm going to be an instructor
as I help guide you through this module.
A module where we're taking a look at the command
arc and different file formats.
As we work our way through this,
we'll be taking a look at our output field separator
variable and how we can use this.
We'll be taking a look at converting files to YAML as well as
reading XML data and creating reports on that.
The first thing we're going to take a look at though
is a challenge arc versus T R.
Now,
we've already seen that we can use the tr command
to convert our field separators, but AC has this built in.
So we don't need to call an additional command.
Let's take a look at how we might do this.
The default output field separator is a space to be able to see this,
we must pass all of our field through as arguments to the print statement.
But if we want to be able to change the O F S, we can set it as our variable.
So here within our org block, we're setting up a begin,
we're specifying our input field separator.
So F S equals colon, we're reading from our past W D file.
We're setting our output field separator to be that glorious comma.
We want a CS V file and we're printing then dollar
$1.03 dollar $4.06 and dollar seven.
We're passing those through as separate arguments separated with a comma.
The comma's there just to separate our arguments and
we're passing through to print, not that we're using that to print the comma.
That's our O F S now, you know, as well as I do,
we can spend our whole time watching slides like this
and although it can be relaxing, maybe even a little so Perri,
it's not what we want to do.
We want to learn.
We really want to learn org.
And the best way to do this is to dive out to our command lines.
So, come on, I challenge you.
We're going to be working with org and the O F S.
We're going to see how we can use the printer statement and different arguments.
But more importantly,
we're going to convert our password file to a CS V file
without having to use the T R command.
Come on,
join me and here we are at our glorious pixel playground and I do hope
you are able to follow through on your own system because we're going to
dive straight in and use the arc command.
You know, we can specify the field separator,
either in our begin block or as an argument to AKS.
So we'll start as an argument to arc.
We're going to make use of the colon as our input field separator.
And then using the single quote,
we can start our AKS statement opening up just our main block to begin with.
We can go through and use our wonderful print command,
printing out some of our fields are dollar one,
the user name and dollar three being the user id of our E T C pass W D file.
But if we just put them in as dollar one and dollar
three with nothing in between them,
then they're going to print as we see route zero _____ one bin two
and so forth with no separator between the fields.
The default output file separator is a space.
But to be able to see that in use, we need to put a comma between our fields.
So they are taken as different arguments.
So we can now see that we've got correctly a look at this.
This is gorgeous root space zero, _____ space one bin, space two and so forth.
There you go.
All that you ever wanted to know about printing with organ,
getting separated fields,
but it's not all you ever wanted to know because what if you
want a different output field separator?
Well, let's go through and do this all within our begin block.
So we'll remove the option minus F and we can use then the
begin block to set our variables in here.
I'm going to use then upper case F S to set the
input file separator to be a colon.
Don't forget to include them in double quotes.
When they're part of code blocks,
we separate our lines of code with a semicolon and then set our
output field separator to be our glorious comma.
We want a comma separated file.
We can close off our block and then go in,
we can print out just the fields we had before.
But why don't we be a little bit extravagant and maybe print out a little
bit more so we can go through and put our group ID D.
So dollar four, we'll skip dollar five.
The os field often that's not populated.
So we can go through and put dollar six being our home directory.
And the last field which is dollar seven,
we can go through and put that in which is our shell.
Now as we go through and hit enter,
remember all of these are comma separated arguments to print.
But now we actually see instead of the space we get in a comma coming out in
our print output because we've set our output field separator without the
need of calling upon the T R command extra processing to go through and run
that we can do it all within org anyway,
that's converting through to CS V.
Its going to be a little bit more complex if we want to convert through to YAML.
But it can be done.
Do you want to see how we can convert our password file to a YAML file?
Go on.
I know you do join me in the next clip where we're going to take a look at that.