Forum Discussion

anupambit1797's avatar
anupambit1797
Steel Contributor
Oct 17, 2024
Solved

TEXT PARSING

Dear Experts,

                     In the Attached text file, each entry has a following structure:-

Reference Signal can be SSB or TRS

and Rx[] ports can go from 0~3,

 

In the output, I need,

Thanks in Advance,

Br,

Anupam

 

6 Replies

    • anupambit1797's avatar
      anupambit1797
      Steel Contributor

      Thanks Lorenzo , meanwhile do you know if and how I can bring all the SNR entry's in the same line as

      their respective RX[] ports? I tried to play something replace etc "   " with "", but nothing worked out.

      In notepad++ how to achieve this?

      Something like below:-

      Thanks in Advance,

      Br,

      Anupam

       

      • Lorenzo's avatar
        Lorenzo
        Silver Contributor

        anupambit1797 

        If this is what you meant (query output):

        In attached file function query:

        // fxAlignRxSnr
        (InputTable as table) as table =>
        let
            Source = InputTable,
            KeptColumn1 = Table.SelectColumns( Source, "Column1"),
            AddedIndex = Table.AddIndexColumn( KeptColumn1, "Index", 0, 1),
        
            FindRx = Table.FindText( AddedIndex, "RX["),
              Rx_FirstPosition = Table.First( FindRx )[Index],
              Rx_ToColumn = FindRx[Column1],
        
            Find_Snr = Table.FindText( AddedIndex, "SNR = "),
              Snr_ToColumn = Find_Snr[Column1],
        
            TableFromColumns = Table.FromColumns(
              { Rx_ToColumn, Snr_ToColumn },
              {"RX", "SNR"}
            ),
            MergedColumns = Table.CombineColumns( TableFromColumns,
                {"RX", "SNR"}, Combiner.CombineTextByDelimiter("", QuoteStyle.None),
                "Column1"
            ),
        
            CombinedTables = Table.Combine(
                { Table.FirstN( AddedIndex, Rx_FirstPosition),  MergedColumns }
            ),
            RemovedIndex = Table.RemoveColumns( CombinedTables, {"Index"} )
        in
            // This prevents the function query to result as error if no "RX[" was found
            if Table.IsEmpty( FindRx ) then Source else RemovedIndex

         

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor

    anupambit1797 

     

    Hi,

     

     

    <?php
    // Define the path to the log file and output CSV file
    $logFilePath = '/storage/emulated/0/Download/SERVING SNR_UE-Log/SERVING SNR_UE-Log.txt';
    $outputCsvPath = '/storage/emulated/0/Download/SERVING SNR_UE-Log/output.csv';

    // Open the log file for reading
    $logFile = fopen($logFilePath, 'r');

    // Check if the file opened successfully
    if (!$logFile) {
    die('Unable to open log file: ' . $logFilePath);
    }

    // Prepare an array to hold the data for the CSV
    $dataRows = [];

    // Temporary variables to store the values we need
    $currentTime = '';
    $currentCellId = '';
    $currentCarrierIndex = '';
    $currentReferenceSignal = '';
    $snrValues = [];
    $rowId=0;

    // Read the log file line by line
    while (($line = fgets($logFile)) !== false) {
    $rowId++;
    // Check if the line contains the date (to capture time)
    if (preg_match('/(\d{4} \w{3} \d{2} \s+(\d{2}:\d{2}:\d{2}\.\d{3}))/',$line, $matches)) {
    $currentTime = $matches[2]; // Extract time
    }

    // Check for Cell Id
    if (preg_match('/Cell Id = (\d+)/', $line, $matches)) {
    $currentCellId = $matches[1];
    }

    // Check for Carrier Index
    if (preg_match('/Carrier Index = (\d+)/', $line, $matches)) {
    $currentCarrierIndex = $matches[1];
    }

    // Check for Reference Signal
    if (preg_match('/Reference Signal = (\w+)/', $line, $matches)) {
    $currentReferenceSignal = $matches[1];
    }

    // Check for SNR values
    if (preg_match('/^\s*SNR = (.+) dB/', $line, $matches)) {
    $snrValues[] = trim($matches[1]); // Collect SNR values
    while (true) {

    $line = fgets($logFile);
    if($line===false) break;
    $rowId++;
    // echo $line;
    if (empty(trim($line))){

    break;
    }
    if (preg_match('/^\s*SNR = (.+) dB/', $line, $matches)) {
    $snrValues[] = trim($matches[1]); // Collect SNR values
    }

    }
    /*
    echo 'rowid'.$rowId;
    die;
    */
    }

    // If we reach the end of a block (next date line), save the current row
    if (empty(trim($line)) && $currentTime) {
    // Format the data for CSV
    $dataRows[] = implode(',', [
    $currentTime,
    $currentCellId,
    $currentCarrierIndex,
    $currentReferenceSignal,
    implode(',', $snrValues)
    ]);

    // var_dump($dataRows);
    // die;

    // Reset temporary values for the next block
    $currentTime = '';
    $currentCellId = '';
    $currentCarrierIndex = '';
    $currentReferenceSignal = '';
    $snrValues = [];
    }
    }

    // Close the log file
    fclose($logFile);

    // Write the data to the CSV file
    $outputCsv = fopen($outputCsvPath, 'w');
    if (!$outputCsv) {
    die('Unable to open output CSV file: ' . $outputCsvPath);
    }

    // Write each row to the CSV
    foreach ($dataRows as $row) {
    fputcsv($outputCsv, explode(',', $row));
    }

    // Close the output CSV file
    fclose($outputCsv);

    echo "Data has been successfully extracted to $outputCsvPath.";
    ?>

     

  • anupambit1797's avatar
    anupambit1797
    Steel Contributor

    Dear Experts,

    I tried to do something like Custom Column.. but not sure on how to map these Rx ports to SNR values, as all 4 have the same indentation..

    Br,

    Anupam

     

Resources