You're viewing a comment by Peter Krumins and its responses.

July 03, 2016, 18:42

There are three parts to your code:

sed -i '/access_log/s|/[^;]\+|/dev/stdout|' /etc/nginx/nginx.conf

First, -i argument that replaces files Inplace, meaning it replaces file content without creating extra files.

Second, /access_log/ code part that makes sed only match lines that contain string "access_log", and apply the command that follows it to these lines.

Third, s|/[^;]\+|/dev/stdout| command.

This command only gets applied to linse that match "access_log".

It's the "s" command meaning substitute (replace).

There are two parts to this substitute command s|FIND|REPLACE| - FIND and REPLACE.

In your code FIND is /[^;]\+ and REPLACE is /dev/stdout.

Your find part is a regular expression that says "start matching at / character and match as many characters as possible [^;]\+ until you hit the ; character."

Your replace part is simply string "/dev/stdout".

Given your input:

access_log /var/log/nginx/access.log main;

The find part in your substitute command matches first / then keeps matching until it hits the ending ; and then replaces it all with /dev/stdout.

Comment Responses

Artym Permalink
July 06, 2016, 05:15

Thank you very much, Peter!

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "apple_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.