Powershell 을 이용한 소스코드 라인 수 세기
리눅스 등에서는 wc –ㅣ 명령을 통해 라인수를 세지만
Powershell 에서는 아래 명령으로 동일한 명령이 가능하다.
아래 명령은 현재 폴더 하위의 C 소스코드 및 헤더 파일의 라인수를 세는 스크립트이다.
Get-ChildItem .\* -Include *.c, *.h -Recurse | Get-Content | Measure-Object –Line
Measure-Object –Line 명령은 자동으로 공백을 제외하고 라인수를 세서 결과를 내 준다.
다음과 같이 profile.ps1 파일에 함수의 형태로 구성해서 사용하는게 편할 것이다.
function sourceLineCH {
Get-ChildItem .\* -Include *.c, *.h -Recurse | Get-Content | Measure-Object -Line
}
Set-Alias lch sourceLineCH
function sourceLineTXT {
Get-ChildItem .\* -Include *.txt -Recurse | Get-Content | Measure-Object -Line
}
Set-Alias lt sourceLineTXT
위 함수를 활용하면 ~
Powershell 에서 lch(line *.c, *.h) 라고 명령을 하면 c, h 확장자를 가진 파일들의 라인수를 세고, lt (line *.txt)라고 하면 txt 파일들의 라인수를 세 준다.