Reading log files or text file is quite basic and log files should be reviewed or else recording the logs if of no point.
PowerShell code below
read the 2nd line of a specific text file specified on the path.
$logs = get-content c:\dev\log1.txt
"Line number 2 in log1.txt is: {0}" -f ($logs[2])
PowerShell code below uses a
loop to read number of lines on a specific text file.
$logs = get-content c:\dev\log1.txt
ForEach ($line_number in 0..10 ) {
"Line number $line_number is :
{0}" -f ($logs[$line_number])}
Using above code, 0 is equal to line 1.
So, to read the first line code should be
like this:
$logs = get-content c:\dev\log1.txt
"Line number 1 in log1.txt is: {0}" -f ($logs[0])
To read the last line:
$logs = get-content c:\dev\xtest.txt -Tail 1
$logs
If above command will return an empty
output, just make sure that the text file does not have any empty spaces at the
bottom of the file.
Cheers...till next time. Stay safe and keep praying that this pandemic will end.
================================
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment