Forum Discussion
anupambit1797
May 01, 2023Iron Contributor
How to use Power Query to parse a txt file
Dear Experts, How to parse a txt file , into excel using Power query for the attached example For example in above , I want to parse all the messages into ex...
peiyezhu
May 01, 2023Bronze Contributor
if possible,upload the txt file and show your expected result.
anupambit1797
May 02, 2023Iron Contributor
- peiyezhuMay 02, 2023Bronze Contributor
I can not figure out which specific table you want。
But I have tried to find one suitable and extracted for you.
I wonder if it is suitable for you with PHP.
But I think you can get the hints such like regular expression etc.
<?php $header="|Number|SCS |Number|Records|ID |RNTI Type |DCI Format |Agg Level |Prune Reason |Layers|K0|Offset|Symbol|ID |Ind |Type|ID |ID |Alloc |Alloc|Mapping|Error |Ind |Ind |MCS|RV|NDI|MCS1|RV1|NDI1|ID |CBGTI|CBGFI|Ack |Index|Group|Ports |Bundling|RMI|CSI|Init|TCI|Ind |FB |DAI|PUCCH|Req|Offset |MISC2 |"; //$line="| 2| 15KHZ| 509| 1| 0| C_RNTI| DL_1_1| LEVEL 4| NOT PRUNED| 1| 0| 4| 0| 1| 0| 0| 1| 1| 512| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 5| 0| 0| 0| 0| 0| 3| 0| 0| 0| 0| 0| 0| 0| 0| 1| 0| 0| 0|"; $files=glob('*.txt'); $handleOut=fopen('fileOut.csv','w'); echo fwrite($handleOut,str_replace('|',",",$header)."\n"); foreach($files as $filename){ $handle = fopen ($filename, "r"); $l=0; while (!feof ($handle)) { $buffer = fgets($handle, 4096); $line = trim($buffer); if(strlen($line)==337){ if(preg_match('{^\|\s*\d\|}',$line)){ echo fwrite($handleOut,str_replace('|',",",$line)."\n"); echo "\n"; $l++; } } // if($l>2) break; } fclose ($handle); } fclose($handleOut);