Posts

Showing posts from February, 2021

Command Prompt Script to Append Flat Files

   Command Prompt 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 Command Prompt script  will be able to resolve this issue: @echo off set "skip=" >summary.txt (   for %%F in (*.csv) do if defined skip (     more +1 "%%F"   ) else (     more "%%F"     set skip=1   ) )

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     }