특정 줄의 특정 부분만 치환하기 정보
Linux 특정 줄의 특정 부분만 치환하기본문
보통 perl -pi -e 이런 형태로 사용을 많이 하는데, 특정줄의 것만 치환할려면 아래 방법을 이용하면 된다.
[root@oracle test]# cat 1.txt
first 111
seconde 111
first 의 111 을 222 로 변경해 보자
[root@oracle test]# sed -r -e '/^first/ s/111/222/g' 1.txt
first 222
seconde 111
정상적으로 변경된것을 확인할 수 있다.
실제 적용을 해 보자.
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
[root@oracle test]# sed -ri -e '/^first/ s/111/222/g' 1.txt
[root@oracle test]# cat 1.txt
first 222
seconde 111
추천
0
0
댓글 0개