Merge Same Structure Text Files with Powershell



$dir = "C:\test\myfolder"
$outFile = Join-Path $dir "FileCombined.txt" 
$fileList = Get-ChildItem -Path $dir\* -Include *.txt -Exclude FileCombined.txt -File
 Get-Content $fileList[0] | select -First 2 | Out-File -FilePath $outfile -Encoding ascii
 
 foreach ($file in $filelist)
{
    Get-Content $file | Select-Object -Skip 2 | Out-File -FilePath $outfile -Encoding ascii -Append
}




--Copy and rename file with appended timestamp

gci -Path 'c:\temp\test\src\' | % {copy $_.FullName "c:\temp\test\dest\$($_.BaseName+$(Get-Date -f yyy-MM-dd-hh-mm)+$_.Extension)"}  
 

http://powershell.com/cs/forums/p/20268/43748.aspx#43748

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s