How to clean up data from multiple files

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
288
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I am not sure what the best course of action would be and if Excel and/or Access would be the best way to handle these issues.

I have two text files each contain a string of ID values separated by commas one file is the "MASTER" list and the other is the "Exception" List

I am looking for a way to get a string that only has the values of the MASTER list except for the EXCEPTION LIST values.

For example the MASTER file has the following contents
12345678,23456789,98765432,87654321,76543210,23723496,23748031,23757919,23854243,23855007,23855155,23856110,23860835,23872391

The EXCEPTION FILE has the following contents
76543210,23723496,23855007

What I would like to return is a string that would contain
12345678,23456789,98765432,87654321,23748031,23757919,23854243,23855155,23856110,23860835,23872391

The Master list could have up to 2000 IDs, each ID is 8 characters long, and it would be presented in a single string in the file.

I am looking for the easiest and best way to process these issues.

Your guidance and suggestions is greatly appreciated.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

kennypete

Active Member
Joined
Apr 19, 2008
Messages
305
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Easy/easiest may be Powershell for this.

Sub out your input master and exception files on lines 1 and 2 and specify where you want the outfile.txt on line 13 and this code should work fine:
Code:
$master = Get-Content "D:\_Share\2021\20210424\master.txt"
$exception = Get-Content "D:\_Share\2021\20210424\exception.txt"

[System.Collections.ArrayList]$arrMaster = $master -split (",")
[System.Collections.ArrayList]$arrException = $exception -split (",")

$arrException | ForEach-Object {
    if ($arrMaster -contains $_) {
        $arrMaster.Remove($_)
    }
}

$arrMaster[0] | Out-File -FilePath "D:\_Share\2021\20210424\outfile.txt" -NoNewline
for ($num = 1 ; $num -lt $arrMaster.Count ; $num++) {
    ',' + $arrMaster[$num] | Out-File -FilePath "D:\_Share\2021\20210424\outfile.txt" -Append -NoNewline
}
Using your input files, this was my output:
1619210572367.png
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,237
Office Version
  1. 2010
Platform
  1. Windows
A VBA demonstration as a beginner starter :​
VBA Code:
Sub Demo1()
  Const D = ",", E = "76543210,23723496,23855007", _
        M = "12345678,23456789,98765432,87654321,76543210,23723496,23748031,23757919,23854243,23855007,23855155,23856110,23860835,23872391"
        V = Split(M, D)
        For Each W In Split(E, D):  V = Filter(V, W, False):  Next
        V = Join(V, D)
        Debug.Print V
End Sub
 

Forum statistics

Threads
1,141,044
Messages
5,703,919
Members
421,321
Latest member
blusky4

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top