Search
Thursday, March 30, 2017 ..:: Home ::.. Register  Login
   Calendar  
     
  
   Search  
     
  
   Blogroll  
     
  
   Disclosure  
All blog entries are the opinions of the author and do not necessarily reflect the opinions of their employer. All the code presented is for explanation and demonstration purposes only. Any damages incurred to your site and/or data are not the responsibility of the author. Every effort is taken to ensure the code properly compiles, however sometimes there are some hiccups and you might be required to do your own debugging.
     
  
   TechTidBits (Blog)  

How do you search LOTS of files for a specific string?

Jan 24

Written by:
Sunday, January 24, 2016 10:12 PM  RssIcon

You have a task to search through hundreds or even thousands of files for a string?image I think I can help out.

At work I have a task to search through directories\files for specific string and I need to do something with them. Doesn’t really matter why, just that I need to do this.  And chances are, if you’re reading this blog, then you’ve had or maybe more importantly, you NEED to do this NOW?!

Well, if this were WHOA! THIRTY years ago, you might have fired up Norton Commander. (I just did the math, it was first released in 1986, WOW!) But alas, time marches on, and so shall we. Ok, so you might then start looking at Windows Explorer, but it’s weak for finding string in files. So what do you do? You probably would reach for the DOS find command, but there again, it’s weak. What to do?

imageLately, I’ve started listening to Sean Kearney on SurfaceSmiths. If you don’t know him, I hope you check out his twitter feed, cause his PowerShell proneness is something to be revered! SO! I thought, HEY! Why not try PowerShell, I’ve heard it’s batch files on STEROIDS! LETS DO THIS!

First off you will need to locate the PowerShell command in windows, it’ll look like this,

image

Then you’ll have a “DOS” looking prompt, but this AIN’T YOUR DADDY’S DOS PROMPT! You have color coding, you have enhanced shortcuts, etc.

image

But, back to OUR story. To help speed up the finding\searching, the quickest way to get this task done, you CD to the dir, then type out something like,

get-childitem –recurse | select-string "the string you wan to find in the THOUSANDS of file to slog through" | group path |select name

I have to get back to my work, I just wanted to share this so I don’t forget later this week. I’ll try to figure out the individual specifics later on, but I hope this helps you as much as it helped me. The only hiccup I have now is trying to escape that inside string to include double quote to search for?! I’ll have to hit up Sean for that!

So now you know how to save a bit of time with searching through files, it’s time to grab a coffee and get coding!

 

Resources

Microsoft Virtual Academy: Getting Started with PowerShell 3.0 Jump Start

TechNet Script Center: Windows PowerShell Scripting

Twitter: Sean Kearney (@energizedtech)

SurfaceSmiths (anything and everything about Microsoft Surface and MANY other things tech, Microsoft, development, support, etc)

Wikipedia: Norton Commander

Tags:
Categories:
Location: Blogs Parent Separator TechTidBits

2 comment(s) so far...


Gravatar

Re: How do you search LOTS of files for a specific string?

Just looking more now, here's another good link to start research off with,TechNet: What can I do with Windows PowerShell? A task-based guide to Windows PowerShell Cmdlets, technet.microsoft.com/en-ca/library/ee332526.aspx
I also LOOOOOOOOVE how powershell remembers your commands (like a stack) between sessions! I used a session last night and I was able to arrow through them just like they were just done now. VERY handy!

By Peter Henry on   Tuesday, January 26, 2016 10:14 AM
Gravatar

Re: How do you search LOTS of files for a specific string?

Thank you so much Sean for reading and for being the inspiration! And thank you for sharing on Twitter that the backtick ( ` ) works as the escape char for the double quote.

By Peter Henry on   Wednesday, January 27, 2016 9:15 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
     
  
Copyright 1999-2012 by PCHenry.com   Terms Of Use  Privacy Statement