노트에버 2018. 10. 10. 19:02

- sed insert text to specific line

sed -i "<line_number>i<anything>" <target_file_name>

직접 text 삽입하는데 사용

- sed search and replace (with regex)

sed -e "s/\(<regex>\|<regex2>\)/repositioned string: \1/g"

Regular expression을 이용해서 search and replace를 수행함. 이때, replace할 문자를 변수로 정의해서 원하는 위치에 다시 넣을 수 있음.

Caution: sed가 platform에 따라 구현이 달라서, -e 옵션보다는 -E 옵션을 사용하는게 더 나음.



출처: http://micol.tistory.com/451 [Young H. Oh]