Feb 06 2022 06:49 PM
what is the best way to get the result of a** d** g** from input of 'abc def ghi'? with the least performance hit.
$test = 'abc def ghi'
((($test -split ' ')).substring(0,1) ) -join ' '
not sure how to add the ** or even a single * will be good. I need to do this to quite a big data, so I need it to run as fast as you can without using the | on each value...
Feb 07 2022 02:22 PM
@dkrabo
Ok, created a file containing this to test on (d:\temp\x.txt in my case)
abc def ghi
jkl mno pqr
stu vwx yz
If I let this script run on it:
foreach ($line in get-content d:\temp\x.txt) {
(((($line -split ' ')).substring(0,1) ) -join ' ').Replace(' ','** ') | foreach {$_ + '**'}
}
This is the output:
a** d** g**
j** m** p**
s** v** y**
Feb 08 2022 06:22 AM
@dkrabo the solution from @Harm_Veenstra seems pretty optimised, testing on a 10,000 line text file it masks all values in about 2s when part of a pipeline.
Feb 08 2022 09:09 AM