Don’t do that #18: Use a loop For to get the line number

By | April 11, 2015

Don’t do that: You want to return the line number of a specific string “user04”.

File.txt

Code:


Do that: A faster method to return the line number is:

(Select-String -Path .\test.txt -Pattern 'user04').LineNumber


previous-buttonnext-button

One thought on “Don’t do that #18: Use a loop For to get the line number

  1. Pingback: Don’t do that #17 : Silent the errors with $ErrorActionPreference = 'SilentlyContinue' - Powershell Guru

Leave a Reply

Your email address will not be published. Required fields are marked *