Solved

Powershell: Find string in a file

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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 …
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

726 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