On unix I can do a
tail -f file
And the equivalent powershell command is
gc file -Wait
However on unix I can press enter to add some blank lines (for readability) on the console while it is outputting lines, but not in powershell. Any workaround?
Use case: On unix I run tail -f /some/webserver/log/file
and it outputs the last part of the log. I then do some http-requests and the log scrolls by accordingly. I then press enter a couple of times to get some blank space in the console, so the log entry for the next request stands out because of the blank lines above.
Using PowerShell newline in Command To add newline in the PowerShell script command, use the` (backtick) character at the end of each line to break the command into multiple lines.
Usage. `n is used in Powershell to append a new line to the standard output. The use of `n in Powershell is similar to \n in C++ or Java. The backtick character (`) represents an escape character in Powershell.
In case you want to run powershell.exe -File from the command line, you always have to set paths with spaces in double quotes (""). Also try using the Grave Accent Character (`) PowerShell uses the grave accent (`) character as its escape character. Just add it before each space in the file name.
% is an alias for the ForEach-Object cmdlet. An alias is just another name by which you can reference a cmdlet or function.
You can use `n to create a new line .
This is just a small example , if you want to modife the out put of the Get-Content command you should store the out put and then and the new line to line 10 for example then retrieve the out put.
write-host "This is an example"
write-host "`n"
write-host "just to show how to add a new line"
This example reads a file and when it get to line to in inserts a space.
$content = Get-Content C:\Dump\test.txt
foreach ($line in $content)
{
if ($line.ReadCount -eq 2) { Write-Host "`n$line" }
Else{$line}
}
This is the out put
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Best way to do blank lines for me is :
""
If you write that in script or console you get a blank line, just two double quotes.
If you want to create for example 3 new blank lines in one shot you could do :
"" ; "" ; ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With