[centos@centos1 ~]$ touch doc{ument,draft} && mkdir {fall,winter,spring}report
[centos@centos1 ~]$ echo "My name is Tom" >tom.txt
[centos@centos1 ~]$ echo "My name is Mary." > mary.txt
[centos@centos1 ~]$ cmp tom.txt mary.txt
# sed
1) head –5 /root/initial-setup | cat –n 해보고,
2) 단어/어구 변경은 's/바뀔_단어/바꿀_단어/' 형식이다.
sed -e 's/System/SYSTEM/g' /root/initial-setup | head
3) 단어/어구 삭제는 '패턴/d' 형식이다.
sed -e 's/System/(빈칸)/gi' /root/initial-setup | head
sed -e 'd' /root/initial-setup | head
=>모든 줄을 삭제하므로 아무 것도 보이지 않는다.
sed -e '4d' /root/initial-setup > /root/initial-setup.bak
sed -e '3,$d' /etc/passwd | head
=>3줄부터 끝줄까지 삭제
sed -e '1,10d' /etc/passwd | head
=>1~10줄까지 삭제
sed -e '/^#/d' /etc/httpd/conf/httpd.conf | head -20
=>주석#으로 시작되는 줄만 삭제. ^#이 부호라는 의미로 전후에 /~/을 붙였다.
sed -e '3,7s/sbin/(빈칸)/g' /etc/passwd | cat –n
=>3~7줄에서 sbin만 삭제
sed -e '/^$/d' /etc/httpd/conf/httpd.conf | cat –n
=>공백 줄만 삭제
sed -e '/^$/!d' /etc/httpd/conf/httpd.conf | cat –n
=>공백 줄만 삭제하지 않음
sed -e '3,7d' /etc/passwd | head | cat –n
=>3~7줄만 빼고 보임
sed -e '/root/d' /etc/passwd | cat –n
=>root가 포함된 줄만 삭제
sed -e '/^#$/d' /etc/httpd/conf/httpd.conf | sed -e '/^$/d' | cat –n
=>주석#과 빈 줄을 모두 삭제
=>sed -i '/^$/d' /etc/httpd/conf/httpd.conf && sed '/^#/d' /etc/httpd/conf/httpd. conf && cat -n /etc/httpd/conf/httpd.conf
=>빈 줄과 주석#을 제외하고 저장함
'Linux > Linux실습' 카테고리의 다른 글
Linux_p #12 (0) | 2023.02.14 |
---|---|
Linux_p #11 (0) | 2023.02.13 |
Linux_p #10 (0) | 2023.02.09 |
Linux_p #9 (0) | 2023.02.07 |
Linux_p #1 (0) | 2023.01.13 |