Windows Powershell: can I split a large SQL file into small files containing one db object
By : Lord Nermal
Date : March 29 2020, 07:55 AM
hope this fix your issue Here's a script that will split your large file into smaller files, starting a new file after each line that contains a semi-colon. It generates the filename based on the first non-blank line following the semicolon (in your example, the two filenames would be CREATE_SET_TABLE_CATALOG.SQL and CREATE_SET_TABLE_CHASSIS.SQL. code :
$buffer = @()
$filename = $null
Get-Content '.\LARGEFILE.SQL' | ForEach-Object {
$line = $_
$buffer += @($line)
if ([String]::IsNullOrWhiteSpace($filename)) {
$filename = $line.Trim().Replace(',','') -replace '[^a-zA-Z0-9_.]+', '_'
}
if ($line.Contains(';')) {
$buffer | Out-File "$filename.SQL" -Encoding utf8
$buffer = @()
$filename = $null
}
}
|
Split a sql file into multiple files using powershell
By : Sandeep
Date : March 29 2020, 07:55 AM
wish of those help Hi I have a single file with multiple(~400) Insert statements like this and I need to split this to multiple files having one insert statement in each of those files. I am guessing it can be done using powershell effectively. , This should help get you going in the right direction: code :
$desktop = [Environment]::GetFolderPath("Desktop") #saving to desktop, adjust as needed
$file = Get-Content "C:\Temp\test.sql" #replace w/ your file location
$content = "" #variable to hold content for each individual file
$pre = "Test_"
$key = ""
$tableName = ""
foreach ($line in $file)
{
if($line -eq "") #if line is blank, export file and reset everything
{
$outFile = $desktop + "\" + $pre + $key + "_" + $tableName + ".sql"
$content | Out-File $outFile
$key = ""
$tableName = ""
$content = ""
}
else
{ #otherwise, collect line
$content += $line + "`r`n"
$words = $line -split " "
if($words[0] -eq "insert") #if this is the insert, take the table name
{
$tableName = $words[2]
}
if($words[0] -eq "values") #if this is the values, take the key
{
$k = $words[1] -split ","
$key = $k[0].Replace("(","").Replace(",","")
}
}
} # end loop
# get last chunk for final file
if($content -ne "")
{
$outFile = $desktop + "\" + $pre + $key + "_" + $tableName + ".sql"
$content | Out-File $outFile
}
|
How can I split a large CSV file into multiple files of rougly equal size using bash tools alone?
By : Levi
Date : March 29 2020, 07:55 AM
|
Split large excel file to multiple smaller file by user defined rows through powershell
By : user1666581
Date : March 29 2020, 07:55 AM
To fix this issue You can utilize an awesome module developed by Doug finke . Import-Excelbelow code will solve you problem. code :
$r=@()
$t=$C=1
Import-Excel -Path C:\Temp\test.xlsx|Foreach-Object -Process {
#Append rows in an array
$r += $_
#Save in a new excel when count reaches 3
if($C -eq 3){
$r | Export-Excel -Path C:\Temp\test_$t.xlsx
#reset values
$r=@()
$c=1
$t++
}
else{
#increment row count
$c++
}
}
#save remaining rows
$r|Export-Excel -Path C:\Temp\test_$t.xlsx
|
How to split war files if the file size is large and deploy it in same context root
By : Justin Zhang
Date : March 29 2020, 07:55 AM
seems to work fine I guess the majority of your WAR file size are libraries under /WEB-INF/lib. You can place most (if not all) JARs in JBoss directly, which will result in very small WAR. Take a look here: Where to put a shared library in JBoss AS 5?
|