Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell-拆分字符串&;将所有文本输出到右侧_Powershell - Fatal编程技术网

Powershell-拆分字符串&;将所有文本输出到右侧

Powershell-拆分字符串&;将所有文本输出到右侧,powershell,Powershell,我有几个文本文件,里面有很多不需要的信息。我基本上希望读取文件的每一行,并将每一行某个短语后的所有内容输出到文本文件中,例如: 一些不需要的垃圾废话一些有用的信息 所以基本上我想遍历每一行,并提取每一行的分词后的所有内容。注意:文本文件仅包含空格作为分隔符 到目前为止,我已经尝试了.substring、.linesplit、转换为CSV和许多其他东西。我觉得这可能是一个非常简单的解决方案,但出于某种原因,我似乎遇到了麻烦!!非常感谢您的帮助 编辑:SPLITPHRASE前后的字符串长度也不是固定

我有几个文本文件,里面有很多不需要的信息。我基本上希望读取文件的每一行,并将每一行某个短语后的所有内容输出到文本文件中,例如:

一些不需要的垃圾废话一些有用的信息

所以基本上我想遍历每一行,并提取每一行的分词后的所有内容。注意:文本文件仅包含空格作为分隔符

到目前为止,我已经尝试了.substring、.linesplit、转换为CSV和许多其他东西。我觉得这可能是一个非常简单的解决方案,但出于某种原因,我似乎遇到了麻烦!!非常感谢您的帮助

编辑:SPLITPHRASE前后的字符串长度也不是固定的

像这样吗

$a = "Some rubbish not needed blah blah SPLITPHRASE Some useful info","Some rubbish not needed  SPLITPHRASE usefull" # can be $a = get-content .\myfile.txt

$a | select-string -patter '(?<=SPLITPHRASE)(.*)'  | 
select -expa matches | select -expa value |  % { $_.trim() }

这正是我想要的,非常感谢你的帮助
Some useful info
usefull