繁体   English   中英

如何使用批处理命令从文本文件中删除 CRLF 和新行

[英]How to remove CRLF and a new line from text file using batch command

目标是使用批处理脚本执行以下操作:

  1. 从 Windows 机器中提取主机名。
  2. 对主机名值应用 sha256 哈希(从步骤 1 中获得)。

我系统的主机名是: W0000000000ZQ

我的批处理脚本如下所示:

@echo off
hostname>hostname.txt
CertUtil -hashfile hostname.txt SHA256 //<- this is generating wrong sha256 string because
                                       //   the above generated file contains CRLF and a new line
                                       //   screenshot of this file provided below.
CertUtil -hashfile hostname-manual.txt SHA256 //<- this is generating correct sha256 string because
                                              //   i manually created this file and pasted hostname
                                              //   only (W0000000000ZQ) without CRLF and new line.
                                              //   screenshot of this file provided below.

主机名.txt:

在此处输入图片说明

主机名手册.txt

在此处输入图片说明

脚本的输出:

在此处输入图片说明

您能否建议如何从“hostname.txt”中删除 CRLF 和换行符,以便 Certutil 选择正确的字符串来生成 sha256 值。

下面将主机名保存到一个没有尾随 CRLF 的文件中。

for /f %%h in ('hostname') do (>hostname.txt <nul set /p unused=%%h)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM