D. Gilliam
D. Gilliam

Reputation: 13

PowerShell Script -replace use

I'm trying to find a line in an SDNF file and replace only part of that line using a PowerShell script.

An example of a line is this:

"L5X5X5/16" "Steel ASTM A36 - PLAN BRACING" 0.000000 0 1 

I need to replace the very last part of the line 0.000000 0 1. I can make it work using the $ anchor but the problem I encounter is that same string occurs at the end of other lines that I don't want to replace. I need a way to limit which lines it replaces that text in. The lines I need to replace all begin with "L..." but the part after that may change. For example it may read:

"L4X4X1/4" "Steel ASTM A36 - PLAN BRACING" 0.000000 0 1

However, The end of the line is always the same.

Upvotes: 1

Views: 66

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

Just add an anchor to match the start of the Text and the first character is a L:

'L5X5X5/16" "Steel ASTM A36 - PLAN BRACING" 0.000000 0 1' -replace '^(L.+)0.000000 0 1$', '${1}YOURREPLACEMENT'

Upvotes: 1

Related Questions