![파일에서 대소문자를 무시하고 검색 문자열의 행 주석 처리를 해제합니다.](https://linux55.com/image/211027/%ED%8C%8C%EC%9D%BC%EC%97%90%EC%84%9C%20%EB%8C%80%EC%86%8C%EB%AC%B8%EC%9E%90%EB%A5%BC%20%EB%AC%B4%EC%8B%9C%ED%95%98%EA%B3%A0%20%EA%B2%80%EC%83%89%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%98%20%ED%96%89%20%EC%A3%BC%EC%84%9D%20%EC%B2%98%EB%A6%AC%EB%A5%BC%20%ED%95%B4%EC%A0%9C%ED%95%A9%EB%8B%88%EB%8B%A4..png)
내 cron 파일 항목은 다음과 같습니다.
#Ansible: test2
*/15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out
# #Cron to auto restart MIMSJASPER tomcat server for all environments if it is down
#Ansible: test3
# */15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out
아래 sed는 대소문자를 구분하지 않고 작동하지 않습니다.
sed '/^#.*morten/s/^#//ig' wladmin.cron
원하는 출력:
#Ansible: test2
*/15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out
#Cron to auto restart MIMSJASPER tomcat server for all environments if it is down
#Ansible: test3
*/15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out
뭔가 제안해주실 수 있나요?
답변1
교체 명령이 아닌 주소 선택에서 대소문자를 구분하지 않도록 해야 합니다. sed의 GNU 구현이 있는 경우 I
다음과 같이 주소 정규식에 대문자 수정자를 적용할 수 있습니다.
sed '/^#.*morten/Is/^#//' wladmin.cron
교체 플래그 g
는 필요하지 않습니다. 실제로 앵커 패턴 인스턴스는 하나만 있을 수 있습니다(예: ) ^#
.