[英]select part of the line from text file in powershell
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 : 我用
select-string -pattern "IM1"
过滤掉了,但是结果是这样的:
19.la1:288:IM1=144_-_1.3.jpg;
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
因此只会出现144 _-_ 1.3.jpg
jpg files would have different names and lengths jpg文件将具有不同的名称和长度
You can split the line on the equel sign, get the last element (-1), and trim the semicolon: 您可以在等号上分割线,获取最后一个元素(-1),并修剪分号:
PS> $line.Split('=')[-1].Trim(';')
144_-_1.3.jpg
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.