[Autogenerated] Oh, look at this a demonstration.
This is really good because this is your time where
you are really going to learn.
So as always, I really do encourage you to join in,
make sure that you do learn this and you,
you do practice it because it is going to pay off by paying off.
I mean that we are going to learn how we can start writing org scripts.
We're going to begin by working with our main code block and looking
at the simple print statement as we go through,
we'll see that we can add line numbers to our output as well,
but we'll start seeing how we might find it better using
print F so we can align our columns nicely.
And this is where we can start beginning to create really good reports.
So take the challenge, come and join me and let master Ork and here we are.
Look at this our glorious pixel playground and I say glorious because this is
where we are going to start to become the master of arc.
So of course, we can just type the command A W K,
we can go through and specify our field separator,
which is going to be a coon.
So minus upper case and F and we're going to be working
with our arc expression so much like said,
we open it with our single quote and then we can work with our main block.
This doesn't take a name,
just open it with our left brace bracket and we can just use print by itself,
close everything off and then reference our input file the forward slash E
T C forward slash pass W D and look just using print,
we're going print each line that matches our expression.
We haven't put an expression in.
So it's going to print out the complete file,
but that's exactly the same as using dollar zero.
Dollar zero in org is the complete row with all of its fields in its glory.
We can also specify the actual fields we want, we don't want the entire row.
We can use dollar one for field one.
You get the idea if we want to go through and maybe
print out field one and field three, we can use dollar one and dollar three,
but don't expect it to put any separation characters between those data.
We have to put in our separating characters.
So you see that we're getting route zero _____ one bin two with
nothing between the user name and the user ID.
If we want something to separate that, then we can put in our own separator.
So we can go through and literally print,
let's say a colon between dollar one and dollar three.
So we can specify exactly how we want the output to appear.
So we can start seeing now that it's working quite well.
But of course,
we have many other tools that are more specialist that does just this.
So again, we want to know why we're going to use arc.
So looking at our expression again, well,
we can start putting a little bit more in if we want.
So we can put in our row number N R and maybe following this,
we can have then a coal an and a space as we then go through.
We can see now we've got line one, line two, line three and so forth.
But obviously, some have got a single number,
whereas others have got double numbers and that's causing us a little bit of
an an alignment issue because when we go from 9 to 10,
you can see that our male and news user don't line up together
because the nine and the 10 are not lining up together.
Now, it's a relatively minor issue.
But remember org is a reporting tool.
So you'd expect it to be able to handle this and handle it really well.
And of course, it does as well as using the print function within org.
We have a print F function and with print F, we're able to format our printing.
Now, this makes reference to our standard C module.
So it's the same as using print F from the command line or print F
modules in many other programming languages.
So again, we have the big advantage much like regular expressions.
We're not just learning it for arc, we are learning how we can use print F.
Now with print F, we can specify our formatting first.
So I'm just going to clear everything out of the way,
go back to print F and I'm going to open up double co click quotes
and I can then specify what I'm expecting to print.
And this is where print F really comes into its own.
Our first element is going to be a number so I can go through and
say per percent two and D for our decimal number.
Now, the idea here is that we have a two digit number.
So per percent is our format specifier D for our numbers.
And I'm specifying that we're allowing two spaces for the number.
Then we have per percent S per percent S is to accept a string.
This string is going to be then our colon and space
separator between our number and our user name.
Now, following that first percent S we can put it in a second per percent.
S and this is going to be for our user name or the dollar one.
After this, we won't bother with the colon.
We'll go straight to dollar three,
but dollar three again is going to be a number,
but we go up to six elements in this when we start looking at our nobody user.
And then following this, we're going to have a new line print,
we'll automatically add in a new line print.
F.
We have to specify the new line.
And once we've got that new line in, we can go through and close our input field,
add in a comma and then we start feeding in our values for the placeholder.
So our first field is going to be the N R for our line number and
let's go through and just tidy everything else up.
Now, just bring it all across and then just comma separate each input value.
The next one is going to be our static string,
which is just going to be our code an and space to separate
our line number from everything else.
Comma dollar one being our user name and then dollar three being our user ID D.
Now this looks quite good when we look at our row numbers,
they're really good, they're all aligned.
But because our user names are very different in length,
it then messes everything else up.
Now, when we take a look at the user names,
its users like system D dash time sync that our our long user names,
they have 20 characters in.
So if we put a string specifier in with a width of 20 characters,
we're going to get magical and nice alignment.
So I just make sure that I go to the right specifier for the string for where
we're accepting our dollar one and I go per percent 20 S,
we can move that to the top, hit the big enter key.
And we can see now because I've specified to allow 20 spaces for our user name.
It all looks perfectly aligned.
So this is a magical reporting tool and with a little bit
of playing around with the formatting, we're able to get everything to align.
Now, one more thing to take a look at is I don't have to print every single row.
If I just want to see lines ending in bash,
then I can add in my normal regular expression ahead of my main block.
And we can see then that we're getting the root user and the
user pi as far as my system is concerned,
when we look at the number of the row, though,
we maintain the record that it was within the original table one and 23.
Its not just one and two here, we're looking at the complete pass W D file.
We'll see though later.
We can count individual records if we so wish.