powershell序列输出逻辑

发布于 2025-02-01 15:35:08 字数 920 浏览 0 评论 0原文

我有一个PowerShell脚本,该脚本将文本文件创建为序列号的输出,从0到10开始(例如)。我必须选择3和5,并以序列顺序创建一个从0开始。我尝试以下脚本,但它不起作用

$afcount=5
for($v=0;$v -lt $afcount; $v++)
{
Get-Content "C:\del2\out($v).txt" | Foreach-Object { 
    if ($_ -match "AI_SERVICE_CONNECTOR") 
    {
        $_    
    }
} | Add-Content "C:\del2\outAI_Service_Connector($v).txt"
$afcount1=(Get-ChildItem -Path "C:\del2\outAI_Service_Connector($v).txt"  -Recurse | Measure-Object).Count
$afcount1
Get-Content "C:\del2\outAI_Service_Connector($v).txt" | Foreach-Object {
    for($i=$null; $i -lt $afcount1; $i++)
    {
        Get-Content "C:\del2\outAI_Service_Connector($v).txt"  | Set-Content "C:\del2\AI_Service_Connector($i).txt"
    }   
}
}

输入文件如下 OUTAI_SERVICE_CONNECTOR(4).txt OUTAI_SERVICE_CONNECTOR(6).txt

期望输出: OUTAI_SERVICE_CONNECTOR(4)要创建为ai_service_connector(1).txt OUTAI_SERVICE_CONNECTOR(6).txt要创建为ai_service_connector(2).txt

I have a powershell script which creates a text file as a output in sequence number starting from 0 to 10(for example). out of which I have to pick 3 and 5 and create a output in sequence order starts from 0. Im trying the below script but it doesnt works

$afcount=5
for($v=0;$v -lt $afcount; $v++)
{
Get-Content "C:\del2\out($v).txt" | Foreach-Object { 
    if ($_ -match "AI_SERVICE_CONNECTOR") 
    {
        $_    
    }
} | Add-Content "C:\del2\outAI_Service_Connector($v).txt"
$afcount1=(Get-ChildItem -Path "C:\del2\outAI_Service_Connector($v).txt"  -Recurse | Measure-Object).Count
$afcount1
Get-Content "C:\del2\outAI_Service_Connector($v).txt" | Foreach-Object {
    for($i=$null; $i -lt $afcount1; $i++)
    {
        Get-Content "C:\del2\outAI_Service_Connector($v).txt"  | Set-Content "C:\del2\AI_Service_Connector($i).txt"
    }   
}
}

Input file as below
outAI_Service_Connector(4).txt
outAI_Service_Connector(6).txt

Expected output:
outAI_Service_Connector(4).txt to be created as AI_Service_Connector(1).txt
outAI_Service_Connector(6).txt to be created as AI_Service_Connector(2).txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文