Now I use get-content to get the file's content, I need to edit some of the lines. For example, change the 2nd line:
before:
line2: hello Everyone!
after:
line2: Hello Mr. Brown!
Which cmdlet can I use?
Now I use get-content to get the file's content, I need to edit some of the lines. For example, change the 2nd line:
before:
line2: hello Everyone!
after:
line2: Hello Mr. Brown!
Which cmdlet can I use?
This will alter the second line (specified through
ReadCount -eq
) toHello Mr. Brown!
. Be sure to use PowerShell 2.0+.If the content is sufficiently unique a replace applied to all lines (but will only match the one you are interested in).
Otherwise load the whole file into a collection, and update the second element (index one).
If the file is large enough that loading the whole file into memory at once is an issue, then something more clever will be needed ….