[Autogenerated] Having dived into our formatting with YAML files.
We're now going to take a look at tagged and XML data.
We can use Apache configuration files and although
they're not entirely XML files, they do use tags in much the same way as XML L.
So we can see here, we've got the start of a virtual host with our opening tag.
We then have settings between their tags and we have
our closing virtual host definition.
Now, for us, we would look at this as being a record,
but it's spent over multiple lines,
which is going to at first give us some problems,
but we're going to learn how to deal with those problems a little bit later on.
Now,
another problem that we might come across though is just the
format of our virtual host files themselves.
When we take a look at this file,
we've got an extra empty line between the document route and the server name.
It's all within one virtual host.
But look when we start another virtual host,
there is no extra or clear line between the virtual hosts.
So this could make it difficult to be able to work with.
So we might decide to tidy up any virtual host configuration
file that we have before we take a look at this and we can
do this with our set command.
You remember sd we looked at that before.
So here we're doing an in place edit.
We're looking for the empty lines and deleting it.
But then we've got another expression where we're looking for lines that
begin with forward slash Vert and app pending a new line.
After that, the new line is back slash and space.
So now we're going to have a blank line between all of our
virtual hosts but not anywhere else in our file.
And this is then going to make it much more easy to be able to report on.
We need to be able to dive out to our command line to take a look at this and
we'll look at formatting our virtual host file using sd two.
First of all, ensure there are no blank lines,
but we have blank lines between our hosts and here we
are at the amazing command line.
Amazing because this is our place where we learn.
And I'm saying that for a couple of reasons,
you know, I'm always keen on your hands on practice really giving you knowledge.
But we're also going to be able to review a little of
what we've seen before with sd.
Although we're looking at org,
we may need sd to help tidy our files to make them easier to work with if
I go through and copy across from our git repository.
So looking in the said an AC directory and looking at our V hosts dot
COF file and just copy that into my test directory.
Now, if I look at this, this is probably in a good condition.
So as I go through and take a look at my vs dot COF,
we can see that this is in good condition.
It's already been edited and put in a nice and workable condition.
However,
very often this is not going to be the case when you're
working with real live configuration files.
So let's go through and edit it with whichever editor you like.
Let's move this to the top of the screen with control an L and
let's start messing it up just a little bit.
So we can add in an extra line there.
Uh We can have,
let's say an extra line here and we might then go through and take it
out the line between our virtual host definition.
Now, already, we can see that even in this format,
it's much more difficult to read now that we've got these extra
lines in place so we can go through and save this.
And of course, that won't have changed anything.
As I go back and look at the file, it's still an absolute mess.
But remember,
we're trying to represent types of files that you
could realistically be coming across.
So if I go through and use my set command,
often it's good not to do the edit straight away.
So let's just display to the screen and we can go through and take a look in
the first instance of looking for a regular expression.
So open up our forward slash where the line begins with optional white space.
So slash S an asterisk followed by the end of line marker,
close our ready expression and then run our command.
So delete.
Now, remember we're not actually editing anything at the moment.
We're only printing to the screen,
but we can check this is working escape and dot to bring up our last argument,
move it to the top of the screen and we can see now that
we've cleared out all of those extra lines.
But we do ideally want to look at each record and the record is between
our virtual host tags to be separated by a clean line.
So for this, I'm going app arrow key,
I'm going to put in an extra set expression by putting a semicolon again,
we're going to look for our regular expression.
So we have our forward slash and we're going to look then for lines that begin
with the less than symbol followed by forward slash V I RT,
I don't need to write the whole thing that should find it.
And that's my regular expression that I am looking for.
However,
the forward slash that we're using with sd is also
the text that we're looking for.
So we could escape our forward slash, we want to append.
So after our closing forward slash, we put the command A for app end,
put a space.
And with this,
we want to go through and make sure that we are adding in
a new line to represent a new line.
We can do that by putting a back slash, followed by a space,
make sure the space is there or it won't work here,
enter and we can see now that the extra blank lines have been deleted.
But after every virtual host tag that's their closing tag,
we've got the extra line.
So now we know that it's working properly,
we can up array and run our said minus I.
So we actually do then run ahead with an in place edit.
This is now going to give me an absolutely glorious file
that I can work with and reading it from the screen is
easy even in a simple format,
but it's going to make it much more easy to be able to process this with our
arc command when we start telling arc what we see as a record separator
rather than taking the default record separator.
So we can have each virtual hosts being a single entry
rather than being spread over multiple lines.