Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Remove rows from a csv file based on the values from the text file

$
0
0

Hi All,

I have a .csv file called input.csv with the following columns.

Columns:

#TYPE Selected.Microsoft.PowerShell.Commands.MatchInfo"Path","Filename","Pattern","LineNumber","Line","APPID","LastWriteTime"

with the sample values below separated by comma and with in double quotes

Sample Values:

"\\XXXXXX\d$\Apps\Archive\XXX-2015-08-14_16-08-34\Service\log4net.xml","log4net.xml","password=|pass=|passwd=|passphrase=|pwd=|psw=|\<password\>","60","              <connectionString value=""data source=SQLSVR;initial catalog=test_log4net;integrated security=false;persist security info=True;User ID=sa;Password=sa""/>","765","7/8/2015 6:03:44 PM""\\XXXXXX\d$\Support\__PACKAGE\Support\Software\PowerShell\Carbon\Service\Install-Service.ps1","Install-Service.ps1","password=|pass=|passwd=|passphrase=|pwd=|psw=|\<password\>","187","            $passwordArgName = 'password='","1310","1/28/2014 4:59:06 PM"

I have a file called exclude.txt  with the value like below which matches the column Line in input.csv

Sample Value in the exclude.txt

"            $passwordArgName = 'password='"

I have written the code below to exclude the line which contains the value in the exclude.txt and put the remaining in an output file.  But it is not working and simple returning all the values in input.csv.  Please review and me know what I a doing wrong here.

$import = @{}


$import = Get-Content C:\PC\Libaudit\input.csv
 select -Skip 1

$database = Get-Content C:\PC\Libaudit\exclude.txt
 
$import |
 where {$_ -notcontains $database} |
 Add-Content C:\PC\LibAudit\ToUpload.csv

Thanks for your help

SS


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>