I have a data file (*.js) per day with the following content:
m[mi++]="26.03.23 23:55:00|0;0;0;2720;0;0;0|488;0;3270"
m[mi++]="26.03.23 23:50:00|0;0;0;2720;0;0;0|1360;0;3220"
m[mi++]="26.03.23 23:45:00|0;0;0;2720;0;0;0|192;0;3110"
...
I would like to merge all files into one file per month. This works with the following command in Windows Powershell:
cat *.js > 2023_04.csv
But before merging, I would like to do a few operations first:
Is this possible in Powershell? If not, what would be the best choice to create a script for this?
I can merge multiple files into one file with the 'cat' command in Windows Powershell.
Done.
# remove old file
if (Test-Path -Path $filename)
{
try { Remove-Item $filename }
catch { }
}
$result
# get all files in current directory with .js extension
$files = Get-ChildItem -Path .\ -Filter *.js
# loop through files
foreach ($file in $files)
{
# read file
$var = Get-Content $file
# reverse file
[array]::reverse($var)
# remove m[mi++]=
$var = $var -replace 'm\[mi\+\+\]\=', ''
# remove double quotes (")
$var = $var -replace '"', ''
# replace | to ;
$var = $var -replace '\|', ';'
# add processed file to result
$result += $var
}
$result | Out-File -encoding ASCII $filename```