Merging two CSV files into one CSV

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of random commandline random commandline 2 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #47163
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Hi,
    I have two IIS logfiles. I am searching a string name: "externalsystemorderservice" and convertin those IISlogfiles to CSV files.
    $log = Get-ChildItem -Path C:\Temp\Test\0.log
    $col = {@()}.invoke()
    switch -Regex -File $log
    {
    '#Fields.*' {$fields = $_}
    '\d+.*externalsystemorderservice.*' {$col.add($Matches[0])}
    }
    $fields = $fields -replace '#Fields:'
    $fields = $fields.trim() -split ' '
    $col -replace ' ',',' | convertfrom-csv -Header $fields |
    Export-Csv -Path C:\Temp\Test\0.csv -NoTypeInformation

    The same way, I am doing for other logfile as-well.

    Problem is, I have common fields in both CSV files & that needs to be merged & come as third CSV file.
    Common fields: date,time,s-computername,s-ip,time-taken.

    -Kalyan

    #47326
    Profile photo of random commandline
    random commandline
    Participant

    Run your switch statement for each log file then export the results. Make the following changes.

    $logs = Get-ChildItem -Path \\path\to\iislogs
    $col = {@()}.invoke()
    
    foreach ($log in $logs){
    switch -Regex -File $log
    {
    '#Fields.*' {$fields = $_}
    '\d+.*externalsystemorderservice.*' {$col.add($Matches[0])}
    }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.