sed는 패턴을 치환해주는 명령이다
sed -e s/[변경 대상 패턴]/[변경 할 패턴]/g [읽어 올 파일]
상세한 옵션은 man sed를 통해 확인 해 보시길
샘플
echo `sed -e 's/127.0.0.1/localhost/g' /etc/hosts`
hosts 파일을 읽어서 127.0.0.1 이라는 문자를 전부 localhost 로 변경한다
마지막에 g 를 넣으면 읽어온 내용 전체를 변경한다는 뜻이고
그렇지 않으면 한 번만 변경한다는 것이다
샘플
echo `sed -e 's/127.0.0.1/localhost/' /etc/hosts`
echo `sed -e 's/127.0.0.1/localhost/g' /etc/hosts`
아래와 같이 패턴을 미리 정의해두고 사용할 수 있다
vi pattern.txt
s/127.0.0.1//g
s/::1//g
s/\(localhost[[:digit:].]*\)*\(localdomain[[:digit:].]*\)*//g
샘플
echo `sed -f pattern.txt /etc/hosts`
'프로그램 > Linux' 카테고리의 다른 글
python daemon 샘플 (0) | 2013.04.16 |
---|---|
linux shell script auto login (0) | 2013.04.12 |
shell script csv 포맷 읽기 (0) | 2013.04.03 |
Linux 방화벽 설정 (0) | 2013.01.12 |
centos5 apache2 설치 (1) | 2012.10.21 |