Created
March 22, 2023 14:11
-
-
Save DineshSolanki/60481e1087528e950d71a89e0a0fe038 to your computer and use it in GitHub Desktop.
remove ansi escape codes from log files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get input path from user | |
$path = Read-Host "Enter file or folder path" | |
# Check if input path is a file or folder | |
if (Test-Path $path -PathType Leaf) { | |
# If path is a file, process it and save output to 'Cleaned' subdirectory | |
$outputPath = Join-Path (Split-Path $path) "Cleaned" | |
New-Item -ItemType Directory -Path $outputPath -Force | |
(Get-Content $path -Raw) -replace "\x1B\[[0-9;]*[mK]" | Set-Content (Join-Path $outputPath (Split-Path $path -Leaf)) | |
} elseif (Test-Path $path -PathType Container) { | |
# If path is a folder, process all files within it and save output to 'Cleaned' subdirectory | |
$outputPath = Join-Path $path "Cleaned" | |
New-Item -ItemType Directory -Path $outputPath -Force | |
Get-ChildItem $path -File | ForEach-Object { | |
(Get-Content $_.FullName -Raw) -replace "\x1B\[[0-9;]*[mK]" | Set-Content (Join-Path $outputPath $_.Name) | |
} | |
} else { | |
Write-Host "Invalid input path" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment