powershell序列输出逻辑
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论