![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Find and GREP i've been using FIND and FINDSTR to search through logs or piped output. It is often compared to the Unix GREP command and I think it works pretty well. However, one feature that I've loved with GREP that is missing from FIND or FINDSTR is the GREP -B switch which prints x lines prior to the matching line, and -A which prints x lines after the matching line. For example say I'm parsing a large log file, and I am searching on an error message. There may be an explanation of why the error occurred on the line before (or after) the line with the error message. That description may not have anything in particular that can be searched on, or I may not know what it is. With the GREP switch I can output my match, but I can also include the lines that give me the information I need. That's just one example, but there are plenty others. Is there a relatively simple command I can run that will do the same thing in Powershell? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Find and GREP Technically, find and findstr aren't part of PowerShell, though they are likely found on any machine capable of running PowerShell. If you're already familiar with grep, I suggest installing that. Sourceforge has a great project which has a number of GNU apps compiled for windows. http://gnuwin32.sourceforge.net/packages.html Mike "swyck" <axlaim@xxxxxx> wrote in message news:1f4615c1-1706-4f45-bf82-5f91a414deef@xxxxxx Quote: > i've been using FIND and FINDSTR to search through logs or piped > output. It is often compared to the Unix GREP command and I think it > works pretty well. > > However, one feature that I've loved with GREP that is missing from > FIND or FINDSTR is the GREP -B switch which prints x lines prior to > the matching line, and -A which prints x lines after the matching > line. > > For example say I'm parsing a large log file, and I am searching on > an error message. There may be an explanation of why the error > occurred on the line before (or after) the line with the error > message. That description may not have anything in particular that > can be searched on, or I may not know what it is. With the GREP > switch I can output my match, but I can also include the lines that > give me the information I need. > > That's just one example, but there are plenty others. Is there a > relatively simple command I can run that will do the same thing in > Powershell? |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Find and GREP Not in v1. In the CTP of v2 Select-String has a -Context parameter. You could include one line before and after of each match like so: select-string <pattern> <logfile> -con 1 # ...or see one line before and three after select-string <pattern> <logfile> -con 1, 3 # for more man select-string -p context -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Find and GREP "Kiron" <Kiron@xxxxxx> wrote in message news:7BD0B808-AC8D-4CBD-9AEC-DBC610558C50@xxxxxx Quote: > Not in v1. In the CTP of v2 Select-String has a -Context parameter. You > could include one line before and after of each match like so: > > select-string <pattern> <logfile> -con 1 > > # ...or see one line before and three after > select-string <pattern> <logfile> -con 1, 3 > > # for more > man select-string -p context > features on Select-String (including -allmatches and -notmatch - think grep -v). -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Commad equal to Grep | PowerShell | |||
| grep -r equiv | PowerShell | |||
| Grep | Vista file management | |||
| select-string to act like grep -v | PowerShell | |||
| Re: grep, which, and tail commands? | PowerShell | |||