get-content | start at line # 100
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
get-content | start at line # 100
How can I get-content of text file and display only one or two lines from that text file starting at a specified line number?
get-content | start at line # 100
How can I get-content of text file and display only one or two lines from that text file starting at a specified line number?
get-content | start at line # 100
Well one way is:
$fileContent = Get-Content 'C:PathToFile.txt'
$fileContent[99..100]
That would get you line 100 and 101.
$fileContent = Get-Content 'C:PathToFile.txt'
$fileContent[99..100]
That would get you line 100 and 101.
get-content | start at line # 100
FYI - some shorthand.
See: help array
Code: Select all
#return lines 4 through 8
(Get-Content 'C:PathToFile.txt')[3..7]
#return line 3, 8 and 10
(Get-Content 'C:PathToFile.txt')[2,7,9]
#return last line
(Get-Content 'C:PathToFile.txt')[-1]
# reverse file lines
$s=Get-Content 'C:PathToFile.txt'
$s[$s.length-1..0]
See: help array