Forum Discussion

anupambit1797's avatar
anupambit1797
Iron Contributor
Mar 01, 2024

Split to values

Dear Experts,

                   I have a txt file m whose structure is like this:-

tci-StateId x,
qcl-Type1
{
bwp-Id 0,
referenceSignal Signal: y,   (Signal can be ssb or csi-rs)
qcl-Type typez( z = A or C)

 

And , with some manual work, I created below table out of it..

Can you please help, if with PQ, we can do this?

 

Thanks in Advance,

Br,

Anupam

 

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor

    anupambit1797 

     

    Try this Go script for reference.

    Rename the attached from .xlsx to .zip and unzip it.

    package main
    
    import (
    	"fmt"
    	"io/ioutil"
    	"os"
    	"regexp"
    	"strconv"
    	/*
    	"strings"
    	*/
    	"encoding/csv"
    )
    
    func main() {
    	// Read the input file
    	data, err := ioutil.ReadFile("pdsch_config_setup.txt")
    	if err != nil {
    		fmt.Println("Error reading file:", err)
    		return
    	}
    
    	// Extract relevant information using regular expressions
    	//regex := regexp.MustCompile(`tci-StateId (\d+),.*?csi-rs : (\d+),.*?qcl-Type (\w+)`)
    	//regex :=regexp.MustCompile(`tci-StateId (\d+),[\s\S]*?csi-rs : (\d+),[\s\S]*?qcl-Type (\w+)`)
    	regex :=regexp.MustCompile(`tci-StateId (\d+),[\s\S]*?(csi-rs|ssb) : (\d+),[\s\S]*?qcl-Type (\w+)`)
    	matches := regex.FindAllStringSubmatch(string(data), -1)
    
    	// Open the output CSV file
    	file, err := os.Create("output.csv")
    	if err != nil {
    		fmt.Println("Error creating file:", err)
    		return
    	}
    	defer file.Close()
    
    	writer := csv.NewWriter(file)
    	defer writer.Flush()
    
    	// Write the header row
    	header := []string{"tci-StateId", "referenceSignal csi-rs", "qcl-Type", "referenceSignal", "referenceSignal Id"}
    	err = writer.Write(header)
    	if err != nil {
    		fmt.Println("Error writing header:", err)
    		return
    	}
    
    	// Write the data rows
    //	for index, match := range matches {
    	for _, match := range matches {
    		tciStateId, _ := strconv.Atoi(match[1])
    		referenceSignal, _ := strconv.Atoi(match[3])
    		qclType := match[4]
    
    		row := []string{
    			//strconv.Itoa(index),
    			strconv.Itoa(tciStateId),
    			strconv.Itoa(referenceSignal),
    			qclType,
    			match[2],
    			strconv.Itoa(referenceSignal),
    		}
    		err = writer.Write(row)
    		if err != nil {
    			fmt.Println("Error writing data:", err)
    			return
    		}
    	}
    
    	fmt.Println("CSV file created successfully.")
    }
    

     

Resources