正则表达式 gawk 匹配

Regular expression gawk matching

我在终端中使用 gawk 来匹配下面文件中的 ALLOWED_HOSTS = [] 行。我正在使用 gawk ' ~ /ALLOWED_HOSTS =.+$/{ print [=12=] }' file_name。我没有得到任何匹配。这很令人费解。我试过使用 /^ALLOWED_HOSTS =.+$/,但没有成功。请查看文本的末尾以查看我要匹配的行。

Django settings for superlists project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4(8f0buww1_&0jqmo-zg89$!epi=zd0)z3v^d+qp&z63fg*bin'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

</code> 仅包含 <code>ALLOWED_HOSTS 标记,不包含该行的其余部分。您想与 [=13=] 进行比较——如果您不提供特定的值进行比较,这无论如何都是隐含的,因此您的整个脚本等同于

gawk '/ALLOWED_HOSTS/' file_name