PowerShell is replacing cmd.exe in the new Windows operating systems, it's more efficient and powerful than its predecessor. The only drawback might be that the commands are much longer than what we used to see in cmd.exe. Counting the lines, words, even the characters are very useful - well, sometimes at least. This task can be easily done using some GUI software such as MS Word, Notepad, or vim if you prefer. PowerShell is capable of doing these jobs as well. Here is how ~ To count the number of lines of a (text) file in Powershell:
Get-Content FILENAME | Measure-Object –LineTo count the number of words of a (text) file in Powershell:
Get-Content FILENAME | Measure-Object –WordTo count the number of characters of a (text) file in Powershell:
Get-Content FILENAME | Measure-Object –CharacterThese options can be stacked together if you like: To count the number of characters of a (text) file in Powershell:
Get-Content FILENAME | Measure-Object –Line –Word –CharacterTo get a specific line from the (text) file, the Get-Content or gc command should work. However, it's slow. According to some test results, the fastest solution would be:
([System.IO.File]::ReadAllLines(FILE_PATH))[LINE_INDEX]
No comments :
Post a Comment