給定一個測試文件settings.py
,看起來像這樣:省略部分
# Django settings for x project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.3/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
我想以編程方式(shell腳本)替換線之間的部分:
DATABASES = {
和:
}
包含在可變k
一些文字:
declare -r k='foo bar baz'
我是一個初學者perl
,但我炮製的:
perl -ne 'if(!$f && /DATABASES/){$f=1} if(!$f){print} if($f && /^}$/){$f=0}' < settings.py
這是我一貫的sed
/awk
小黑客出發:
# e.g.
sed '/DATABASES/,/^}$/ d' < settings.py
我想提高我的perl
單線!
我該怎麼辦sed
在全能的perl
中做得如此精美?
什麼是絕對的最佳途徑:
- 手錶標準輸入經過,重現它到stdout
- 檢測哨兵「停止印刷」行並停止複製
- 重新啓用的傳遞stdin->標準輸出當遇到第二個哨兵線
我省略了任務的更換部分,希望能得到一些幫助機智h也是如此。
我想用sed的'/ DATABASES /,/ ^} $ /'是rougly日同['/ DATABASES/... /^}$/'](http://perldoc.perl.org/perlop.html#Range-Operators)。 –