

Or we could instead use 2>&1 which is a fancy syntaxįor saying "redirect standard error to the same Standard error to the same file, we could do ls docs > output.txt 2> output.txt If we wanted to redirect both standard output and cat bees.txt ants.txt > insects.txt 2> error.txt Insects.txt, and redirecting standard error to a file called error.txt. We can redirect multiple streams at once! In this example, we areĬoncatenating two files, redirecting standard output to a file called To specify 1> to redirect standard output: ( date 1> now.txt = date > now.txt) all together The > operator actually defaults to using 1 as theįile descriptor number, which is why we don't need In both cases, you see the entire log buth with highlighted search term like this: The -f switch could be omitted if no live grep is wanted.
You could use block comments to embed comment text within a command: Get-Content -Path < configuration file > C:\config.ini. In PowerShell 2.0 and above multi-line block comments can be used: < Multi Line >.The grep utility allows a user to search text using some different options, but this utility doesn't exist in Windows.
#Powershell grep a line code#
If the container logs to stderr, you can pipe them as Edoardo already wrote for a simple grep: docker logs -f 2>&1 | grep -line-buffered -i -E -color "select count\(\*\)|$" Single line comments start with a hash symbol, everything to the right of the will be ignored: Comment Here. When writing PowerShell code and you need to search for text inside of a single string or an entire text file, where do you turn If you've used Linux very much, you're probably familiar with the popular grep utility. * is escaped to disable its special glob functionality, where (, and ) are masked to avoid their regex meaning as group, which is enabled by -E switch.-color highlights the matched parts (seems the default behaviour on my Ubuntu 16.04 LTS, but maybe not on other distributions, so I included it here to be safe).-E is an extended regex pattern, required to apply our pattern that allow us returning also the non matching results.greps -line-buffered switch flushes the output on every line, which is required to grep in real time when docker logs -f is used.docker logs -f tell docker to follow the logs, so the filter applys also to new entrys like when viewing it using tail -f.This is possible with -E switch and some regex:įor example, the following snippet search for all queries that contain COUNT(*) as well as count(*): docker logs -f | grep -line-buffered -i -E -color "select count\(\*\)|$" But with a simple grep I can't see the entire SQL statement since it's a multi line statement. In my case I want to highlight COUNT(*) statements. For example, the following command displays all lines containing ERROR in a text file or stdout: Select-String -Path c:tmpmakeappsxtracesxs.txt -Pattern 'ERROR'. In PowerShell, you can use the Select-String cmdlet to find a text string in a file.

Especially on productive installations where a lot of log output is generated. Grep allows you to find/select any data in the output of another command: command grep search. Additionally, I found it usefull to highlight some terms that I'm searching for in the logs.
