Input file contains few lines which are broken into 2 lines. The below logic works fine and checks if a line contains [" but does not contain "] then it concatenates line 1 & 2.
Existing working logic
Code: Select all
$file = Get-Content -Path "C:\temp\sinput.txt" -Raw
$file = $file -ireplace '(?<match1>\[\"[^\]]*)\r\n(?<match2>[^\]]*\"\])','${match1}${match2}'
$file
["ef
gh"],
gets corrected as in output
["efgh"] which is good.
Q1:
How to change the above logic to check if a line contains [" but does not contain ], then it concatenates line 1 & 2.
I tried: efgh works as expected so far but misses out the next line after "point of care"
Code: Select all
$file = Get-Content -Path "C:\temp\sinput.txt" -Raw
$file #show input file
$file = $file -ireplace '(?<match1>\[\"[^\]]*)\r\n(?<match2>[^\]]*\]\,)','${match1}${match2}'
$file
How to remove leading spaces (if any) on line 2 before concatination.
I tried: trim function but i'm new to ps and im sure i made some mistake
Code: Select all
$file = Get-Content -Path "C:\temp\sinput.txt" -Raw
$file = $file -ireplace '(?<match1>\[\"[^\]]*)\r\n(?<match2>[^\]]*\"\])','${match1}${match2}.trim()'
$file
Line 2 has encoding characters. Team Lead's (single quotes does not work as expected)
I know this works.
get-content C:\temp\pinput.txt -Encoding UTF8 | Set-Content c:\temp\poutput.txt
But when i try the below it doesnt work. i know im new and i think im not doing it right.
Code: Select all
$file = Get-Content -Path "C:\temp\sinput.txt" -Raw
$file = $file -ireplace '(?<match1>\[\"[^\]]*)\r\n(?<match2>[^\]]*\"\])','${match1}${match2}.trim()'
$file = $file -Encoding UTF8
$file