The Grep equivalent in powershell named Select-String

Search text or patterns in input strings and / or files with the Select-String powershell command.
Select-String is the powershell equivalent like Grep in Linux.
Below are some examples, how you can use it.

Search in all the  *.txt files on the C:\tmp directory for the string floor:

				
					PS C:\Users\sande>  Select-String -Path c:\tmp\*.txt -Pattern floor

C:\tmp\file1.txt:5:floor
C:\tmp\file2.txt:6:1st floor
C:\tmp\file3.txt:5:2nd floor
				
			



Get-ChildItem

The Get-ChildItem is using the -recurse parameter to get one or more child-items in that path, and redirects (with | ) the output to the Select-String command. 

Search in all *.txt files located in C:\tmp and  subdirectory’s (recursive) for the string floor:

				
					Get-ChildItem -Path c:\tmp\ -Recurse | Select-String -Pattern door

C:\tmp\file1.txt:1:door
C:\tmp\file2.txt:2:doorbell
C:\tmp\file3.txt:2:doorbell
C:\tmp\Sub-Directory\file4.txt:2:doorpost
				
			

 

Select-String

With Select-String you can find a string in a file. It uses regular expression matching to search for patterns in the file. 

Search in all *.txt files located in C:\tmp and  subdirectory’s (recursive) for the string floor:

				
					Select-String -Path c:\tmp\*.txt -Pattern 'Type-'

C:\tmp\file1.txt:3:$BigHouse = Type-House
C:\tmp\file2.txt:4:$MyHouse = Type-House
C:\tmp\file3.txt:1:$LargeHouse = Type-House
				
			
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
bash-script

Use Autopwn plugin in Metasploit for automatic exploitation

Next Post

Install Android 9 as virtual machine in Vmware