Reputation: 1
Im trying to select part of the line from text file
i used select-string -pattern "IM1"
to filter out but the outcome is like this :
19.la1:288:IM1=144_-_1.3.jpg;
i just want the outcome to be from = to ; so only 144_-_1.3.jpg would appear
jpg files would have different names and lengths
Upvotes: 0
Views: 4467
Reputation: 126932
You can split the line on the equel sign, get the last element (-1), and trim the semicolon:
PS> $line.Split('=')[-1].Trim(';')
144_-_1.3.jpg
Upvotes: 4
Reputation: 4104
You could use a regular expression:
$line='19.la1:288:IM1=144_-_1.3.jpg'
$regex = [regex]'={1}(.*\.jpg)'
$regex.Match($line).Groups[1].Value
Upvotes: 0