I'm confused by a portion of the below command.
awk '/<Directory \/>/,/AllowOverride None/{sub("None", "All", $0)}{print}' /etc/apache2/apache2.conf > myfile.txt
The command replaces
<Directory />
AllowOverride None
</Directory>
with
<Directory />
AllowOverride All
</Directory>
in the Apache configuration, and writes the updated configuration to myfile.txt
.
I don't understand how the command is pattern matching across two lines of the file. None of the examples that I've been able to find work across lines. I'm guessing it has something to do with the comma in /<Directory /\>,/AllowOverride
, but I'd like to understand exactly what's going on. How is this pattern match being done across two lines of the file?
Also, why is {print}
necessary? Doesn't awk
print its results by default?