is there a way to use foreach and replace on text file to change a character with linebreak and x number of indents? Peculiar request, but it is to make it readible in another program.
Sample text:
dyreriket|{Animalia}
!leddormer@{Annelida}
¤igler${Clitellata}
The symbols |, !, @, ¤, $ and many more should be replace with linebreak and a given number of indents. I can make the indents work, but not the linebreaks. There is no response when using `n, it only removes the original character. So far I’ve been playing around with this code.
$t1 = '\@';
$r1 = "`n`t`t";
$t2='\¤';
$r2="`n";
Get-Content C:\arter\test.txt `
| ForEach-Object { $_ -creplace $t1, $r1; } `
|ForEach-Object { $_ -creplace $t2, $r2; } `
| Out-File C:\arter\test2.txt ;
You can do a line-by-line text replacement like this:
That uses regular expression character classes to replace all occurrences of the
|,!,@,☼, or$characters inInput.txtwith a linefeed followed by a carriage return followed by two tabs and writes the resulting text toOutput.txt. To perform a case-insensitive search, use the-replaceor-ireplaceoperators.