Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- import
- Windows
- vscode
- IntelliJ
- Eclipse
- profile
- 단축키
- Windows 10
- context
- xargs
- plugin
- GIT
- Quartz
- Mac
- resource
- netsh
- Source
- bash
- maVen
- tomcat
- 네트워크
- lsof
- ssh
- JavaScript
- find
- port
- web.xml
- 줄바꿈 문자
- grep
- VirtualBox
Archives
- Today
- Total
develog
[mac] grep --include, sed 로 특정 확장자 파일 내용 바꾸기 본문
확장자가 .sh 인 파일을 찾고 '찾을문자열' 을 '바꿀문자열' 로 변경한다
grep 사용
# 확장자가 .sh 인 파일 대상으로 '찾을문자열'을 찾는다
grep -r --include='*.sh' '찾을문자열' .
# 확장자가 .sh, .txt 인 파일에서 찾는다
grep -r --include='*.sh' --include='*.txt' '찾을문자열' .
# 확장자가 .sh, .txt 인 파일에서 찾는다 (다른 방법)
grep -r --include='*.'{sh,txt} '찾을문자열' .
grep -rl 로 파일을 찾고 xargs sed 로 내용을 변경한다
# 파일을 찾고 내용을 변경한다
grep -rl --include='*.sh' '찾을문자열' . | xargs sed -i '' 's/찾을문자열/바꿀문자열/g'
find 사용
find . -name '*.sh' | xargs sed -i '' 's/찾을문자열/바꿀문자열/g'
# 경로에 공백이 있는 경우도 성공
find . -name '*.sh' -exec sed -i '' 's/찾을문자열/바꿀문자열/g' {} \;