问题描述
- shell脚本修改文件部分内容
- 问题描述:想修改文件指定内容 但是行数过多 用sed感觉过于繁琐 有没有像echo一样直接追加到指定位置然后注释原有内容之类的方法?
感觉自己钻牛角尖了 没有想明白 求指教
随便截个代码片段做例子# for all of them.LOCAL_PATH = '/tmp'SECRET_KEY='e9c3b51c80a59a17ba8e'# We recommend you use memcached for development; otherwise after every reload# of the django development server you will have to login again. To use# memcached set CACHES to something like#CACHES = {# 'default': {# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache'# 'LOCATION': '127.0.0.1:11211'# }#}CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' }}# Send email to the console by defaultEMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'# Or send them to /dev/null#EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'# Configure these for your outgoing email host#EMAIL_HOST = 'smtp.my-company.com'#EMAIL_PORT = 25#EMAIL_HOST_USER = 'djangomail'#EMAIL_HOST_PASSWORD = 'top-secret!'# For multiple regions uncomment this configuration and add (endpoint title).#AVAILABLE_REGIONS = [# ('http://cluster1.example.com:5000/v2.0' 'cluster1')# ('http://cluster2.example.com:5000/v2.0' 'cluster2')#]OPENSTACK_HOST = ""127.0.0.1""OPENSTACK_KEYSTONE_URL = ""http://%s:5000/v2.0"" % OPENSTACK_HOSTOPENSTACK_KEYSTONE_DEFAULT_ROLE = ""_member_""# Enables keystone web single-sign-on if set to True.#WEBSSO_ENABLED = False# Determines which authentication choice to show as default.#WEBSSO_INITIAL_CHOICE = ""credentials""比如将下面内容 CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' }}# Send email to the console by defaultEMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'# Or send them to /dev/null#EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'修改为 CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' ‘localhost':'127.0.0.1' '1111111':'22222' }} Send email to the console by default#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' Or send them to /dev/nullEMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
解决方案
你这个,通过SED命令,在指定行后面添加内容就行了呀。
在指定行后插入一行
sed '2 attt' -i a.txt #在第2行后插入ttt并且将结果更新到a.txt(如果不想更新原文件,去掉-i)
解决方案二:
用c修改文件中部分内容
时间: 2024-09-17 04:52:30