![sed + 줄 방지를 위해 "#" 문자 제거](https://linux55.com/image/120610/sed%20%2B%20%EC%A4%84%20%EB%B0%A9%EC%A7%80%EB%A5%BC%20%EC%9C%84%ED%95%B4%20%22%23%22%20%EB%AC%B8%EC%9E%90%20%EC%A0%9C%EA%B1%B0.png)
우리는 다음과 같은 파일을 가지고 있습니다:
cat graphite-web.conf
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
# Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
"모든 권한 부여 필요" 행 앞의 #을 제거하는 가장 좋은 방법은 무엇입니까
- "#" 문자가 줄 시작 부분에 없습니다.
예상 출력:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
답변1
sed해결책:
sed 's/#\([[:space:]]*Require all granted\)/ \1/' graphite-web.conf
산출:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
파일을 그 자리에서 편집하려면 - -i
옵션을 추가하세요:
sed -i ....