正则表达式gawk匹配

时间:2016-07-17 03:56:00

标签: regex gawk

我在终端中使用gawk来匹配下面文件中的ALLOWED_HOSTS = []行。我正在使用gawk '$1 ~ /ALLOWED_HOSTS =.+$/{ print $0 }' 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

1 个答案:

答案 0 :(得分:1)

$1仅包含ALLOWED_HOSTS令牌,而不包含该行的其余部分。您希望与$0进行比较 - 如果您没有提供要比较的特定值,则暗示这是隐含的,因此您的整个脚本等同于

gawk '/ALLOWED_HOSTS/' file_name