6
2
I realize I'm asking a similar question that was already asked and answered but I was not able to extrapolate the answer I needed since the regex and regex engine is different enough. I have hardware asset management logs which are pipe delimited but not are major delimited between endpoints. The logs look like this:
|STATUS1|HOSTNAME1|IP1|MAC1|IS_WIRED1|STATUS2|HOSTNAME2|IP2|MAC2|IS_WIRED2|STATUS3|HOSTNAME3|IP3|MAC3|IS_WIRED3
What I would like to do is replace every 6th |
with a carriage return to look like this:
|STATUS1|HOSTNAME1|IP1|MAC1|IS_WIRED1
|STATUS2|HOSTNAME2|IP2|MAC2|IS_WIRED2
|STATUS3|HOSTNAME3|IP3|MAC3|IS_WIRED3
The closest I've gotten selects each endpoint but I'm not quite sure how to utilize it using powershell.
[^\|]*\|[^\|]*\|[^\|]*\|[^\|]*\|[^\|]*\|[^\|]*
I'm familiar with the replace command in PS and I'm imagining the end result would be something to this effect:
$hosts = $hosts -replace "<highspeed_low_drag_velcro_snap_regex_here>","\r\n"
Thanks in advance!
@JakeGould I would consider this a bit of a special case, because the OP is specifically seeking a PowerShell solution. Not only is it a different regex engine (.NET vs the PCRE that Notepad++ uses), but the replacement text is actually specified differently too. – Bob – 2018-01-03T03:36:39.093