Mar 01 2024 12:18 PM
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
Mar 01 2024 07:15 PM
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.")
}
Mar 02 2024 01:14 PM
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
Mar 02 2024 03:22 PM
Mar 09 2024 10:53 AM
Thanks@peiyezhu , in general if I have to learn only one Language for Data-manipulation and cleaning(ETL), then what it should be python or php? I heard python is more easier and lesser code lines than other languages..
Br,
Anupam
Mar 09 2024 11:27 AM
Mar 09 2024 03:25 PM - edited Apr 06 2024 02:59 AM
Yes. Python is a great option which has many resources.
If you use the codes for yourself,I recommend Python.
Go,C# and php also great.
php is easy to start and good at web program.
Go,C# dotnet for desktop and can be compiled to Exe.
Apr 05 2024 05:24 AM
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...