Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

Filename C:\Before.txt contains 2 lines and a 3rd blank line: 0401f048abe933348f09…

  1. User

    Filename C:\Before.txt contains 2 lines and a 3rd blank line: 0401f048abe933348f09 E823_8FA6_BF53_0001_001B_444A_49F9_57C1.

    Create a powershell script to read in each line, check if line length is between 18 and 22, and output the result into a new text file.

  2. Assistant

    Here's an example of a PowerShell script that reads each line from the input file, checks if the line length is between 18 and 22 characters, and outputs the result into a new text file:

    $inputFile = "C:\Before.txt"
    $outputFile = "C:\After.txt"
    
    $lines = Get-Content $inputFile
    $filteredLines = foreach ($line in $lines) {
        $lineLength = $line.Length
        if ($lineLength -ge 18 -and $lineLength -le 22) {
            $line
        }
    }
    
    $filteredLines | Out-File $outputFile
    

    Make sure to replace "C:\Before.txt" with the actual path to your input file and "C:\After.txt" with the desired path for the output file.