It will be hard and probably error prone to recommend something meaningful when we do not know what you’re actually trying to do.
Your code is a weird mix of PowerShell and dotNet and is badly formatted. Could you please explain with a few words what your goal is, what your situation before is and what the expected result is?
(When you post smaple data, please format it as code as well. Thanks in advance.)
I have this txt file. I need replace tab to semicolon and replace dot to comma in price
my export file
condition transaction: 111111111
Items: all
text2: 4604 VS old XS expire price sender
2536985678 25.5.2022 10.96 Stephan
1111000001 25.5.2022 600 John
2222275016 25.5.2022 8.04 Andy
count: 3 suma 619
Depending on your actual structure in your input file you have several options to extract the data from it. You may watch this video to get an idea what’s possible:
Yes it would. But you did not provide enough information to recommend something meaningful. For the particular sample input text you posted it could be done like this:
$InputText = @"
my export file
condition transaction: 111111111
Items: all
text2: 4604 VS old XS expire price sender
2536985678 25.5.2022 10.96 Stephan
1111000001 25.5.2022 600 John
2222275016 25.5.2022 8.04 Andy
count: 3 suma 619
"@
foreach ($line in $InputText) {
$line -replace '(?<=\d{1,2}\.\d{1,2}\.\d{4}\s+\d+)\.(?=\d+)',','
}
I would suggest to use a more object based input file, like xml or json. Plaintext is unstructured by default and you need all kinds of regular expressions to solve problems that would not exist if one used structured input. If you are not able to use a normal/modern input (probably Unix or Linux output) you will be stuck with terrible regexes that potentially break with every little change in the input file. Parsing text files is a painful process, just ask any Unix or Linux guy, they are aware of the horror involved I hope you are able to change your input format, otherwise you can talk with the Unix and Linux guys