Solved

Powershell: Find string in a file

Posted on 2016-09-22
3
44 Views
Last Modified: 2016-09-23
Hello experts,

I have an input file containing some strings, one per line. I have data dump csv file. I need to output the lines from the data file containing the lines that match the string in the input file.

Could you please help me with a script.

Thanks
0
Comment
Question by:Parity123
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41811121
Here is a simple code, check and let me know if it works for you..
$words = (GC C:\input.txt) -join "|"
GC C:\Test.csv | ? {$_-Match $words} | Out-File C:\newfile.csv

Open in new window

Sample C:\input.txt
Test
Text
abc

Open in new window

Code will search any lines which contains Test, Text or abc in C:\Test.csv and out put to C:\newfile.csv

If this doesn't work for you, then provide and sample csv file and the input file..
0
 

Author Comment

by:Parity123
ID: 41812821
Thanks Subsun. It works
0
 

Author Closing Comment

by:Parity123
ID: 41812824
Thanks
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Synchronize a new Active Directory domain with an existing Office 365 tenant
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question