Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell: Find string in a file

Posted on 2016-09-22
3
Medium Priority
?
66 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

636 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