So this should be an easy task in theory, but for the life of me I can’t seem to figure it out. Goal is to stop after a number of matches are found and end out of a loop. Here is a snippet with example data:
$csv = @" id,first_name,last_name,email,gender,ip_address 1,Parnell,de Keyser,pdekeyser0@xrea.com,Male,105.107.108.138 2,Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101 3,Astra,Harmeston,aharmeston2@tinyurl.com,Female,151.59.164.215 4,Danielle,Lochhead,dlochhead3@senate.gov,Female,180.170.27.16 5,Chickie,Goodlatt,cgoodlatt4@pen.io,Female,19.125.145.111 6,Ossie,Layborn,olayborn5@dailymail.co.uk,Male,53.42.93.62 7,Collin,D'Onise,cdonise6@skype.com,Male,252.134.190.197 8,Erastus,Negus,enegus7@biblegateway.com,Male,52.68.109.153 9,Angy,Syseland,asyseland8@clickbank.net,Female,121.59.129.236 10,Orran,Palumbo,opalumbo9@webs.com,Male,148.28.44.254 Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, Wilden,Dicte,wdicte1@ucla.edu,Male,8.25.66.101, "@ | ConvertFrom-Csv -Delimiter ',' $patternmatch = $csv | Select-String -Pattern 'wdicte1@ucla.edu' do { $patternmatch } until ($patternmatch.count -le 5)
Basically I want to stop once I have 5 matches. The reason for this is searching through multiple log files and I want to review the data from the last five matches. I can’t figure out how to stop the processing once five matches are found. Thanks in advance for your help. I don’t want to use | select -first 5 as it still has to find all matches then filter the first matches.
submitted by /u/Jayj0ka
[link] [comments]
The post Do-until Loop appeared first on How to Code .NET.