如何在 Windows Server 上的文件中显示行尾和控制字符?

如何在 Windows Server 上的文件中显示行尾和控制字符?

我的 Windows 服务器出现了一些问题,我需要在 Puppet 运行中添加 --server,否则它就无法工作,尽管配置文件中设置了正确的服务器。我想知道是否有 Linux 行尾而不是 Windows crlf。从 Windows 框中检查这一点的简单方法是什么?

答案1

或者使用快速 VBS 破解:

'
' Save this as "myscript.vbs" and then execute from command line like:
'   cscript.exe myscript.vbs "<file to check>"
'
Option Explicit
On Error Resume Next
Err.Clear
Dim objArgs
Dim objFSO
Dim objTextFile
Dim strFileContentsIn
Dim strFileContentsOut
Dim intCharIndex
strFileContentsOut = ""
Set objArgs = WScript.Arguments
If Err.Number <> 0 Then
    WScript.Echo "ERROR : Bad args."
    Err.Clear
Else
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    If Err.Number <> 0 Then
        WScript.Echo "ERROR : Failed to create File System Object."
        Err.Clear
    Else
        Set objTextFile = objFSO.OpenTextFile( objArgs.Item(0) )
        If Err.Number <> 0 Then
            WScript.Echo "ERROR : Failed to open file."
            Err.Clear
        Else
            strFileContentsIn = objTextFile.ReadAll
            If Err.Number <> 0 Then
                WScript.Echo "ERROR : Failed to read file."
                Err.Clear
            Else
                For intCharIndex = 1 To Len( strFileContentsIn )
                    If ( Asc(Mid( strFileContentsIn, intCharIndex, 1 )) = 10 ) Then
                        strFileContentsOut = strFileContentsOut & "\n" & VbCrLf
                    ElseIf ( Asc(Mid( strFileContentsIn, intCharIndex, 1 )) = 13 ) Then
                        strFileContentsOut = strFileContentsOut & "\r"
                    Else
                        strFileContentsOut = strFileContentsOut & Mid( strFileContentsIn, intCharIndex, 1 )
                    End If
                Next
                WScript.Echo strFileContentsOut
            End If
            objTextFile.Close
            Set objTextFile = Nothing
        End If
        Set objFSO = Nothing
    End If
End If

替代的、更短的 PowerShell 版本。仍然不是本机命令:\

(([IO.File]::ReadAllText( "<filepath>" ) -replace "`r", "\r") -replace "`n", "\n")

相关内容