Solved

Powershell: Find string in a file

Posted on 2016-09-22
3
30 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now