# Find match string in csv

**URL:** <https://forums.powershell.org/t/find-match-string-in-csv/20520>\
**Category:** PowerShell Help\
**Created:** [September 25, 2022, 5:18pm UTC](https://forums.powershell.org/t/find-match-string-in-csv/20520 "2022-09-25T17:18:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dras](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dras/32/2654_2.png) [@dras](https://forums.powershell.org/u/dras)\
**Post date:** [September 25, 2022, 5:18pm UTC](https://forums.powershell.org/t/find-match-string-in-csv/20520/1 "2022-09-25T17:18:16Z")

</div>

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.

```auto

# 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
}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 25, 2022, 5:31pm UTC](https://forums.powershell.org/t/find-match-string-in-csv/20520/2 "2022-09-25T17:31:12Z")

</div>

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

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dras](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dras/32/2654_2.png) [@dras](https://forums.powershell.org/u/dras)\
**Post date:** [September 25, 2022, 6:11pm UTC](https://forums.powershell.org/t/find-match-string-in-csv/20520/3 "2022-09-25T18:11:46Z")

</div>

formating is fixed, hope you can help ! thank you

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 25, 2022, 6:48pm UTC](https://forums.powershell.org/t/find-match-string-in-csv/20520/4 "2022-09-25T18:48:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/find-match-string-in-csv/20520/5 "2024-05-16T20:16:35Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


