Find match string in csv

Hello some one know how to get this.

I have multiple csv`s . I want to pull a string from those.
Becasue the number is multiple times in the file I only want the hace the first hit.


# First Script: Collect csc_reader.serial_number from Bit files


$Files   = Get-ChildItem  "C:\temp" -Filter *.csv
$outfile = "C:\Temp\output\output.csv"


foreach ($csv in $files){
    
    
    $Csv -match '4100\w+' 
    $Matches

    #Out-File $outfile
}

# Second script: - collect csc_reader.serial_number from Bit files


#
$Files   = Get-ChildItem  "C:\temp" -Filter *.csv
$outfile = "C:\temp\output\output.csv"


foreach ($csv in $files){
    
    Write-Host "Export csc_reader.serial_number from $csv"
    Import-Csv  $csv.FullName | Select csc_reader.serial_number, network.hostname, rtc | select -First 1 |  # where {$_.rtc -like "Wed, 21 Sep 2022*"} | select  -First 1 `
    Export-Csv $outfile 
    Out-File $outfile
}

Before we proceed … please edit your question once more and fix the formatting of your code.

Thanks in advance.

formating is fixed, hope you can help ! thank you

It is actually unclear to me what you’re really looking for.

For your “first script” - don’t you know in what column you expect the search pattern to be? You may share a few sanitized lines of an input CSV file (formatted as code as well please) and the expected output.

For your “second script” - you commented out some code what actually breaks your code. Here I’d recommend the same - share some sample data and the expected output, please.