Is there a performant way to do this? I’ve been investigating [Linq.Enumerable]::Where() but keep hitting the error “Index operation failed; the array index evaluated to null.” even when I’m just trying examples from the web.
[Linq.Enumerable]::Range(0, $products.Count).Where({param($i) $products[$i] -match "8"})
Index operation failed; the array index evaluated to null.
At line:1 char:63
+ ... Range(0, $products.Count).Where({param($i) $products[$i] -match "8"})
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
Index operation failed; the array index evaluated to null.
At line:1 char:63
+ ... Range(0, $products.Count).Where({param($i) $products[$i] -match "8"})
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
Index operation failed; the array index evaluated to null.
At line:1 char:63
+ ... Range(0, $products.Count).Where({param($i) $products[$i] -match "8"})
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
This code is just a way to demonstrate the problem I’m trying to solve which is why it’s a little odd.
Hi. Thanks or the formatting suggestion. I just copied it from my test scenario but you’re right that it is easier to read in a forum when it is formatted sensibly
I agree with the “Select-String” suggestion but this is part of a wider problem I’m trying to solve:
CSV file with embedded LF within the text and LF as the end of line
Replace the embedded LF but not the end of line
Using ConvertFrom-Csv, it splits at the the end of line characters (into an object array of PSCustomObjects) but retains the embedded LF characters. If I can then track down the values (e.g. description in one row) that contain these embedded LF characters, I can escape them. Using only regex, I have to be sure that the LF character I’m finding is genuinely embedded and not an end of line.
Hi again. Yeah I’ve been looking at a regex pattern and it’s close but the ConvertFrom-Csv was handling a lot of embedded quotes in the data, etc. and I was hoping this could be a shortcut to a solution. There are 299 columns in the input file!
Hmm … does it have to be that complex? Depending on how your input data really look like and if every single cell is wrapped in double quotes I’d start with a simple negative lookahead. I mentioned that before. I’d look for a line break character NOT followed by a double quote.