Powershell Script to Append Flat Files

 Powershell Script to Append Flat Files



There was a requirement to merge \ append multiple flat files within one folder and in addition - it should also be able to read header file from 1st file but then remove header row from other subsequent flat files 


Below Power shell script  will be able to resolve this issue:




$getFirstLine = $true


get-childItem "C:\temp\Mergefiles\LS_CTD_PYMTHIST_NF*.txt" | foreach {

    $filePath = $_


    $lines =  $lines = Get-Content $filePath  

    $linesToWrite = switch($getFirstLine) {

           $true  {$lines}

           $false {$lines | Select -Skip 1}


    }


    $getFirstLine = $false

    Add-Content "LS_CTD_PYMTHIST_NF.txt" $linesToWrite

    }


Comments

Popular posts from this blog

Calculating Age of the person in T-SQL

How to Troubleshoot Subscription issue in Reporting Services

MDX Queries - Current Day - Month and Year