Looking at the file in Notepad, all seems fine but then I use PS to Get-Content into an array, then have a For loop to examine each line and output each line to a file. The outputted content appears to be ok EXCEPT EVERY character is surounded by a space. In the file you may see something like: THIS IS DATA but my program output reads: T H I S I S D A T A
Nick,
Welcome to the forum. ![]()
Instead of describing your code you should share it.
(formatted as code, please)
Without seeing your actual code all we can do is guessing. Did you check the encoding of your files?
Thank you Olaf for your interest. I am on holiday at the moment. I will return next week, however I will try to update this query when I get to the hotel
![]()
So you left right after you posted this question?
Didn’t you expect someone to answer? ![]()
function edit1
{
v9 check for tag surrounded by test 8
cls
echo "[[[[[[[[[[[[ start ]]]]]]]]]]]]]]]]]]"
$line_number = 0
$line1_found = "0"
$buffer = "empty"
$first_of_pair
$OutPutFileName = "D:\OneDrive\Documents\COMPUTING\SCRIPTING AND PROGRAMMING\POWERSHELL\F_easeus_output.txt"
if (Test-Path $OutPutFileName) {
Remove-Item $OutPutFileName
}
$input_array = Get-Content "D:\onedrive\documents\COMPUTING\SCRIPTING AND PROGRAMMING\POWERSHELL\easeus.log"
foreach ($line in $input_array) {
$line_number = $line_number + 1
echo "processing line $line_number $line"
if ( $line -match "2021-12-22")
{
$line | out-file -filepath $OutPutFileName -append
}
#if ( ($line -match "2021-12-05") -and
# ($line -match "GetNextRun start"))
if ($line_number -gt 17000)
{
echo "stopped at requisite line number"
echo $OutPutFileName
exit
}
#echo $input_array[3]
}
"all over" | out-file -filepath $OutPutFileName -append
echo 'lines read = ' $line_number
echo "[[[[[[[[[[[[ ends ]]]]]]]]]]]]]]]]]]"
}
edit1
the input fie that I am trying to read is 598Kb - How do I upload it to my post so you can see it (or a small part of it) ? Thanks for your patience
First of all …
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
How to format code in PowerShell.org 1 <---- Click
![]()
( !! Sometimes the preformatted text button hides behind the settings gear symbol.
)
I’d recommend to upload only a small - but at least representative - part of it, formatted as code as well. This way we could copy it and use it for own tests if needed.
Regardless of that … with a quick overlook over your code …
Have you tried specifying the encoding for the input and output files?
And please: Do not use aliasses. They make your code much harder to read and to understand.
Here you can read more about:
Hi Olaf, where do I use alias in my code? I do not think I use them
Olaf appears to be on Holiday ![]()
get-alias echo
Hey @nic67 if you could post a sample portion of your log file with just a few lines in it (please format it as code) then we can try and take a look. Your log file is very specific to your issue that I can not reproduce it.
2023-12-12 09:30:48 [M:17,T/P:17252/15096] [UILogic] UILogicCallBackFunc leave
2023-12-12 09:30:48 [M:28,T/P:17252/15096] Wallace - [Transmit type : 0, Call UI with activate command and result : 0]
2023-12-12 09:30:48 [M:29,T/P:7868/5436] Ldq : Agent receive data from client and error = 0x0
2023-12-12 09:30:48 [M:28,T/P:17252/15096] Wallace - [Transmit type : 0, Send active result to agent : 0]
sorry Olaf I cannot see in my code the get-alias you mention…
2023-12-12 09:30:48 [M:17,T/P:17252/15096] [UILogic] UILogicCallBackFunc leave
2023-12-12 09:30:48 [M:28,T/P:17252/15096] Wallace - [Transmit type : 0, Call UI with activate command and result : 0]
2023-12-12 09:30:48 [M:29,T/P:7868/5436] Ldq : Agent receive data from client and error = 0x0
2023-12-12 09:30:48 [M:28,T/P:17252/15096] Wallace - [Transmit type : 0, Send active result to agent : 0]
ty
function edit1
{
# v9 check for <a> tag surrounded by <p></p> test 8
cls
echo "[[[[[[[[[[[[ start ]]]]]]]]]]]]]]]]]]"
$line_number = 0
$line1_found = "0"
$buffer = "empty"
$first_of_pair
$OutPutFileName = "D:\OneDrive\Documents\COMPUTING\SCRIPTING AND PROGRAMMING\POWERSHELL\F_easeus_output.txt"
if (Test-Path $OutPutFileName) {
Remove-Item $OutPutFileName
}
$input_array = Get-Content "D:\onedrive\documents\COMPUTING\SCRIPTING AND PROGRAMMING\POWERSHELL\easeus.log"
foreach ($line in $input_array) {
$line_number = $line_number + 1
echo "processing line $line_number $line"
if ( $line -match "2021-12-22")
{
$line | out-file -filepath $OutPutFileName -append
}
#if ( ($line -match "2021-12-05") -and
# ($line -match "GetNextRun start"))
if ($line_number -gt 17000)
{
echo "stopped at requisite line number"
echo $OutPutFileName
exit
}
#echo $input_array[3]
}
"all over" | out-file -filepath $OutPutFileName -append
echo 'lines read = ' $line_number
echo "[[[[[[[[[[[[ ends ]]]]]]]]]]]]]]]]]]"
}
edit1pe or paste code here
as you see, I have found out how to paste the coded ‘formatted’ as requested by enclosing it between </>
echo is an alias of Write-Output
I can’t replicate the problem you’ve described with your code using the sample data. Is this the full code? You have two unused variables $line1_found and $buffer.
As already suggested, this could be an encoding problem. If you copy and paste the sample you posted above into a new file (just create a blank file in Notepad) and use that as the input file, do you get the same problem?
Thanks Matt, I did what you suggested (cut and pasted 20 lines from the original file [easeus.log] into a new file) Reading in this new file works fine and the output is as expected with no spaces around the characters. So the code is ok, there is something odd obout the easeus.log It is the logfile from the backup software I use: EaseUS Todo Backup It’s Properties show it as a simple text file
It seems I am only allowed to upload one screenshot/image per post so I will upload them separately

I would suspect an encoding issue on the text file. On line 14 try adding -Encoding followed by either ASCII, Unicode or UTF8 and see if one of those fixes the issue. I would try UTF8 first.
Get-Content <file_path> -Encoding UTF8

