Forum Discussion
Power Query or any other solution
- Sep 22, 2024
anupambit1797 In case you are still interested in a PQ solution, the attached file contains a pretty straight-forward one. Just change the source path to the correct location on your own system and see it it produces the correct results.
Re:Power Query or any other solution
PHP as other solution
<?php
function parseBody(){
$files=glob('*.txt');
$handleOut=fopen('fileOut.csv','w');
$pattern='/Slot\|Frame\|Timetick\|PDU/';
foreach($files as $filename){
$handle = fopen ($filename, "r");
$new_line="";
$prefix="";
$rowId=0;
$blnNewLine=false;
while (!feof ($handle))
{
$buffer = fgets($handle, 4096);
$rowId++;
$line = trim($buffer);
if(preg_match('/2024 /',$line,$m)){
$prefix=$line;
}
if(preg_match($pattern,$line)){
$blnNewLine=true;
$buffer = fgets($handle, 4096);
// $line = trim($buffer);
$rowId++;
}else{
if(empty($line) && $blnNewLine==true){
$blnNewLine=false;
}
if(!empty($line) && $blnNewLine==true){
echo $line."\t";
echo $rowId."\n";
// die;
$new_line=str_replace('|',",",$line);
//$new_line.=str_replace('|',"\t",$line);
$new_line=trim($new_line,',');
//$new_line=rtrim($new_line,"\t");
$new_line=$prefix.','.$new_line."\r\n";
// $new_line.= $rowId."\n";
fwrite($handleOut,$new_line);
}
}
}
fclose ($handle);
}
fclose($handleOut);
}
parseBody();