使用批处理处理文本文件

发布于 2025-01-22 15:34:08 字数 508 浏览 1 评论 0原文

我是批处理脚本的新手,想与内容一起处理我的输入文件:

MD5 hash of sample.js,
81f87dd81ef88f59a57d95d9ede5f92e
MD5 hash of searchReplace.js,
3493b216e1024f0d6de417ef6c8b3962
MD5 hash of Select Anything.js,
009f2b911b50550502b87aeeeb969b55

输出应该看起来像:

MD5 hash of sample.js,81f87dd81ef88f59a57d95d9ede5f92e
MD5 hash of searchReplace.js,3493b216e1024f0d6de417ef6c8b3962
MD5 hash of Select Anything.js,009f2b911b50550502b87aeeeb969b55

 Can someone please help me out with it ?

I am new to batch scripting and would like to process my input file with the content :

MD5 hash of sample.js,
81f87dd81ef88f59a57d95d9ede5f92e
MD5 hash of searchReplace.js,
3493b216e1024f0d6de417ef6c8b3962
MD5 hash of Select Anything.js,
009f2b911b50550502b87aeeeb969b55

The output should look like :

MD5 hash of sample.js,81f87dd81ef88f59a57d95d9ede5f92e
MD5 hash of searchReplace.js,3493b216e1024f0d6de417ef6c8b3962
MD5 hash of Select Anything.js,009f2b911b50550502b87aeeeb969b55

 Can someone please help me out with it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难得心□动 2025-01-29 15:34:08

尝试以下操作:

@echo off
setlocal enableDelayedExpansion
set "info_file=.\example1.txt"

for /f "useback tokens=* delims=" %%a in ("%info_file%") do (
    set "line=%%a"
    if "!line:~0,3!" EQU "MD5" (
        set "to_echo=!line!"
    ) else (
        set "to_echo=!to_echo!,!line!"
        echo !to_echo!
    )
)

endlocal

try this:

@echo off
setlocal enableDelayedExpansion
set "info_file=.\example1.txt"

for /f "useback tokens=* delims=" %%a in ("%info_file%") do (
    set "line=%%a"
    if "!line:~0,3!" EQU "MD5" (
        set "to_echo=!line!"
    ) else (
        set "to_echo=!to_echo!,!line!"
        echo !to_echo!
    )
)

endlocal
撩心不撩汉 2025-01-29 15:34:08

这起作用:

@echo off
setlocal

call :procFile < input.txt > output.txt
goto :EOF


:procFile
   set /P "line1="
   if errorlevel 1 exit /B
   set /P "line2="
   echo %line1%%line2%
goto procFile

您也可以通过 /f < /code>命令通过读取文件:

@echo off
setlocal EnableDelayedExpansion

set "line="
(for /F "delims=" %%a in (input.txt) do (
   if not defined line (
      set "line=%%a"
   ) else (
      echo !line!%%a
      set "line="
   )
)) > output.txt

This works:

@echo off
setlocal

call :procFile < input.txt > output.txt
goto :EOF


:procFile
   set /P "line1="
   if errorlevel 1 exit /B
   set /P "line2="
   echo %line1%%line2%
goto procFile

You may also read the file via a for /F command this way:

@echo off
setlocal EnableDelayedExpansion

set "line="
(for /F "delims=" %%a in (input.txt) do (
   if not defined line (
      set "line=%%a"
   ) else (
      echo !line!%%a
      set "line="
   )
)) > output.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文