get-content, last five lines

get-content c:\myfile gets and displays the contents of the file myfile.txt.  You can put the data into a variable and use it later.  If  you only want the end of the file, you can deal with it in the variable, or just select initially the first two or last five rows

$a = {get-content C:\myfile.txt)[1 .. 3]
$a = ()[-1 .. -5]

Two meatballs and the minus sign counts from the sinister end. Ah, if the text is right to left, i guess the end of the data is on the right side of it, which would be the “dexter” end.  Who is kinda sinister.

A different way would be to either use -totalcount or |select-object -last X or -first X

$a = gc C:\myfile.txt |select-object -first 10
$a = gc C:\myfile.txt |select-object -last 10
$a = gc C:\myfile.txt -totalcount 10
# drop the comment line
$a = gc C:\myfile.txt |select-object -skip 1

.


		
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.