我找到了powershell脚本来查找包含“示例字符串”的每一行,但是具有我想要的字符串的每一行也都有一个3位数字。我只对数字感兴趣,它在使用powershell脚本找到的行中始终处于同一位置。因此,我真正需要的是一个脚本,该脚本查找带有“示例字符串”的行,然后从字符串中提取char x-y并将它们输出到文件中。
07.10.2018 20:48:36 Total speed: 599 Sol/s 07.10.2018 20:49:06 Total speed: 601 Sol/s 07.10.2018 20:49:36 Total speed: 600 Sol/s
我使用当前脚本获得以上输出。我只想拿个电话号码
使用以下代码:
class SemesterController extends Controller
{
public function iterateOverCourcesOfGivenSemester()
{
// take first semester as an example.
$givenSemester = Semester::first();
// all the cources belongs to a given semester.
$cources = $givenSemester->cources;
foreach($cources as $cource) {
// Warning! don't echo anything in a controller, Instead return them to a view.
echo $course->Number, " - ", $course->Title;
echo "<br>";
}
}
}
我得到以下结果:
54C 598 Sol/s 598 598 598 [A:124, 598 [A:97, 598
答案 0 :(得分:1)
这显示了两种从样本字符串中获取“总速度”数字的方法。没有您的代码,您将需要找出在您的设置中可以使用它的人。 [咧嘴]
app.use('/your_secure_path', dummyMiddleware);
两个主题都给出样本中包含的# fake reading in a text file
# in real life, use Get-Content
$InStuff = @'
07.10.2018 20:48:36 Total speed: 599 Sol/s
07.10.2018 20:49:06 Total speed: 601 Sol/s
07.10.2018 20:49:36 Total speed: 600 Sol/s
'@ -split [environment]::NewLine
foreach ($IS_Item in $InStuff)
{
# split on the space, then take the 2nd from the end
$IS_Item.Split(' ')[-2]
# capture the numbers after "speed: " and before " Sol"
# store them in a named group = "Speed"
# get the group from the $Matches automatic variable
$Null = $IS_Item -match 'speed: (?<Speed>\d+) Sol'
$Matches.Speed
''
}
数字。
希望有帮助,
李
答案 1 :(得分:0)
谢谢@Lee_Dailey的脚本。我对其进行了一点编辑,我得到的正是我想要的输出:
$InStuff = sls -path Z:\logfile.log -pattern "Total speed" | select-object -Last 5
foreach ($IS_Item in $InStuff) {
$Null = $IS_Item -match 'speed: (?<Speed>\d+) Sol'
$Matches.Speed
}