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 typ...
peiyezhu
Mar 02, 2024Bronze 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.")
}
anupambit1797
Mar 02, 2024Iron 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
- peiyezhuMar 02, 2024Bronze 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.- anupambit1797Mar 09, 2024Iron Contributor
Thankspeiyezhu , 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
- peiyezhuMar 09, 2024Bronze Contributor
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.