Forum Discussion
anupambit1797
Mar 01, 2024Iron Contributor
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
- peiyezhuBronze Contributor
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.") }
- anupambit1797Iron Contributor
Thanks peiyezhu , but as mentioned earlier, I am not a coder , looking for something in Power Query, with the Power Editor steps to achieve this.
Thanks,
Br,
Anupam
- peiyezhuBronze ContributorThanks for your response.
Yes,I see.
As part of brain storm in this forum,I just provide it for reference rather than standard answer.
I guess PQ here may need regular expression too.
So,maybe help to some PQ expert.
On the other hand,here I guess you also need codes with M language (https://powerquery.how/#:~:text=The%20M%20language%20Power%20Query%20M%2C%20a%20language,the%20Power%20BI%2C%20Excel%2C%20and%20other%20Microsoft%20products.) rather than only click and drag drop.
- LorenzoSilver Contributor
Update the path (in the Source step) to the text file in the attached query and if your actual file is as consistent as the one you shared that should work...