Solved

Powershell: Find string in a file

Posted on 2016-09-22
3
52 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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