Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Drop non-matching records in TXT file

$
0
0

Hello sir,

I need some help with manipulating the data in a txt file. 

here is an example ;

 

File 1:

ProductName

AAAA

B

CCCC

D

EEE

 

File 2:

ProductNameUPC, Quantity

AAAA 123, 100

CCCC 234, 200

D 456, 300

FF 678, 500

 I want to delete records from File 2 if the product name  is NOT present in  File 1

 

Updated file should look like below:

ProductNameUPC, Quantity

AAAA 123, 100

CCCC 234, 200

D 456, 300

 

I’m new to powershell but still tried the below code using some research but its giving error. Any help with this request is greatly appreciated.

$csv=ConvertFrom-Csv $txt

 

$symbol=ConvertFrom-Csv $symb

 

$newcsv=$csv|?{$symbol.'<symbol>' -contains $_.'<name>'.Split()[0]} 

0 0 1 67 388 LACOE 3 1 454 14.0 Normal 0 false false false EN-US JA X-NONE

Thank you in advance.


Viewing all articles
Browse latest Browse all 6937

Trending Articles