Привет!
- User
Привет!
- Assistant
Привет! Чем могу помочь?
- User
Можешь переписать скрипт, написанный на windows cmd на powershell?
- Assistant
Конечно! Пожалуйста, предоставьте мне скрипт на Windows cmd, чтобы я мог переписать его на PowerShell.
- User
@echo off setlocal enabledelayedexpansion
set "inputFile=test.txt" set "tmpFile=tmp.txt"
if exist "%tmpFile%" del "%tmpFile%"
set "line1=" set "line2=" set "line3=" set /a "flag=0"
:again set /a "containsSlashes=0" for /f "delims=" %%a in (%inputFile%) do ( if "!line1!"=="" ( set "line1=%%a" ) else if "!line2!"=="" ( set "line2=%%a" ) else ( set "line3=%%a" echo "!line2!" | findstr /C:"///" >nul && ( echo !line1! - !line3! >> "%tmpFile%" set "line1=" set "line2=" set "line3=" set /a "flag=1" set /a "containsSlashes=1" ) || ( echo !line1! >> "%tmpFile%" set "line1=!line2!" set "line2=!line3!" set "line3=" ) ) )
if %flag%==0 ( if not "!line1!"=="" echo !line1! >> "%tmpFile%" if not "!line2!"=="" echo !line2! >> "%tmpFile%" if not "!line3!"=="" echo !line3! >> "%tmpFile%" )
move /Y "%tmpFile%" "%inputFile%" if %containsSlashes%==0 ( endlocal exit )
echo "Repeat again" goto again
- Assistant
Вот ваш скрипт на PowerShell:
$inputFile = "test.txt" $tmpFile = "tmp.txt" if (Test-Path $tmpFile) { Remove-Item $tmpFile } $line1 = "" $line2 = "" $line3 = "" $flag = 0 $containsSlashes = 0 do { Get-Content $inputFile | ForEach-Object { if ($line1 -eq "") { $line1 = $_ } elseif ($line2 -eq "") { $line2 = $_ } else { $line3 = $_ if ($line2 -match "///") { Add-Content -Path $tmpFile -Value "$line1 - $line3" $line1 = "" $line2 = "" $line3 = "" $flag = 1 $containsSlashes = 1 } else { Add-Content -Path $tmpFile -Value $line1 $line1 = $line2 $line2 = $line3 $line3 = "" } } } if ($flag -eq 0) { if ($line1 -ne "") {Add-Content -Path $tmpFile -Value $line1} if ($line2 -ne "") {Add-Content -Path $tmpFile -Value $line2} if ($line3 -ne "") {Add-Content -Path $tmpFile -Value $line3} } Move-Item -Path $tmpFile -Destination $inputFile -Force } while ($containsSlashes -eq 1) Write-Host "Repeat again"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.