복수 개의 파일의 내용을 변경

-- PowerShell 2011. 8. 16. 18:09
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

이번에는 PowerShell 이용해서대량의파일을대상으로내부내용을 변경하는방법을찾아보았습니다. PowerShell 에는 -replace 연산자가존재하는데, 마치 리눅스의 sed 명령어처럼 있습니다.

 

"wow nice olleh" | %{$_ -Replace ("nice","OLLEH")}
 

만약, "MyDocument" 디렉터리및하위디렉터리의 모든 *.txt 파일을대상으로파일내용 "nice" "OLLEH" 라고바꾸고싶다면, 아래명령어를사용하면됩니다.

 

dir -Path MyDocument -Include *.txt -Recurse | %{$tmp = Get-Content $_; $tmp=$tmp -Replace ("nice","OLLEH"); Set-Content $_ $tmp}
 

파일의내용 nice 모두 OLLEH 변경것을확인있습니다.

출처 : http://blog.daum.net/sharer77/6900209

'-- PowerShell' 카테고리의 다른 글

PowerShell로 웹소스 가져오기  (0) 2011.08.17
zip파일 다루기  (0) 2011.08.16
PowerShell 선언된 변수  (0) 2011.08.16
컴퓨터에 메모리 종류 확인  (0) 2011.06.24
The VBScript-to-Windows PowerShell Conversion Guide  (0) 2011.06.22
posted by 어린왕자악꿍