How do I go about removing the end of line when going through a TXT file line by line? What I want to do is produce a simple TSV but I want lines starting with "ES-ES " to be a column after the normal text.
I'm loading the XML like this to get clean text from the elements:
[xml]$xml = Get-Content -Path PATH/TO/XML.xml
$tmx.tmx.body.tu.tuv > C:\Users\XXX\test.txt
Then doing some changes to it (remove 3 header lines, trim trailing spaces and replace lines that start with "ES-ES " with a tab) like this:
$outfile = "C:\Users\XXX\test.txt"
$lines=(Get-Content $outfile) |select -Skip 3 | foreach{ $_.Trim() -replace "ES-ES ","`t"}
$lines > $outfile
But I can't seem to be able to remove the "`n" at the end of the previous line (because I'm going through it line-by-line, maybe?). How would I concatenate "TEST " lines with the previous line?
Thanks.
EDIT:
Example of the XMLs that I have (it's a simple translation memory XML - TMX).
<?xml version="1.0" encoding="UTF-16LE"?>
<!DOCTYPE tmx SYSTEM "tmx14.dtd">
<tmx version="1.4">
<header o-tmf="TW4Win 2.0 Format" creationtool="XXX" creationtoolversion="3.XX" segtype="sentence" datatype="PlainText" adminlang="EN-US" srclang="EN-GB">
</header>
<body>
<tu creationdate="20XX" creationid="XXXXX">
<prop type="Year">20XX</prop>
<prop type="Database">General</prop>
<tuv xml:lang="EN-GB">
<seg>Segment with original text in source language (English).</seg>
</tuv>
<tuv xml:lang="ES-ES" changedate="20XXXXXXXXXXX">
<seg>Segment with translated text in target language (Spanish).</seg>
</tuv>
</tu>
<tu creationdate="20XX" creationid="XXXXX">
<prop type="Year">20XX</prop>
<prop type="Database">General</prop>
<tuv xml:lang="EN-GB">
<seg>Another segment with original text in source language (English).</seg>
</tuv>
<tuv xml:lang="ES-ES" changedate="20XXXXXXXXXXX">
<seg>Another segment with translated text in target language (Spanish).</seg>
</tuv>
</tu>
<tu creationdate="20XX" creationid="XXXXX">
<prop type="Year">20XX</prop>
<prop type="Database">General</prop>
<tuv xml:lang="EN-GB">
<seg>Yet another one in English</seg>
</tuv>
<tuv xml:lang="ES-ES" changedate="20XXXXXXXXXXX">
<seg>Yet another one in Spanish</seg>
</tuv>
</tu>
And the output I want is:
Segment with original text in source language (English). Segment with translated text in target language (Spanish).
Another segment with original text in source language (English). Another segment with translated text in target language (Spanish).
Yet another one in English Yet another one in Spanish
I'm sure this could be done better in python or something, but I don't have permissions or access to any coding tools except for powershell. :\