Batch file 如果存在特定字符,则在行中追加

Batch file 如果存在特定字符,则在行中追加,batch-file,Batch File,我有这个文本文件 通过使用批处理文件,如果大写字母为W,我想显示“anger”,如果字母为F,则表示“happy”,N表示“neutral”。有可能吗 我想要这样 03a01Fa.wav 03a01Nc.wav 03a01Wa.wav 提前感谢,期待解决方案 03a01Fa.wav,happy 03a01Nc.wav,neutral 03a01Wa.wav,anger 您可以使用FIND以另一种方式查看批处理文件中的阵列管理: @echo off setlocal EnableDelayed

我有这个文本文件

通过使用批处理文件,如果大写字母为W,我想显示“anger”,如果字母为F,则表示“happy”,N表示“neutral”。有可能吗

我想要这样

03a01Fa.wav
03a01Nc.wav
03a01Wa.wav
提前感谢,期待解决方案

03a01Fa.wav,happy
03a01Nc.wav,neutral
03a01Wa.wav,anger

您可以使用
FIND
以另一种方式查看批处理文件中的阵列管理:

@echo off
setlocal EnableDelayedExpansion

rem Define the equivalences array
for %%a in ("W=anger" "F=happy" "N=neutral") do (
   for /F "tokens=1,2 delims==" %%b in (%%a) do (
      set "append[%%b]=%%c"
   )
)

for /F %%a in (theFile.txt) do (
   set name=%%a
   for /F %%b in ("!name:~5,1!") do echo %%a,!append[%%b]!
)
如果需要文件(
output.txt
)中的输出:

@echo off
setlocal EnableDelayedExpansion

rem Define the equivalences array
for %%a in ("W=anger" "F=happy" "N=neutral") do (
   for /F "tokens=1,2 delims==" %%b in (%%a) do (
      set "append[%%b]=%%c"
   )
)

for /F %%a in (theFile.txt) do (
   set name=%%a
   for /F %%b in ("!name:~5,1!") do echo %%a,!append[%%b]!
)
@echo off

for /f  "delims=" %%a in (file.txt) do  (
   echo %%a | find "F">nul && echo %%a,happy
   echo %%a | find "N">nul && echo %%a,neutral
   echo %%a | find "W">nul && echo %%a,anger)
@echo off
for /f  "delims=" %%a in (file.txt) do  (
   echo %%a | find "F">nul && echo %%a,happy
   echo %%a | find "N">nul && echo %%a,neutral
   echo %%a | find "W">nul && echo %%a,anger)>output.txt
@echo off
    setlocal enableextensions disabledelayedexpansion

    (for /f "usebackq" %%a in ( "wavfile.txt" ) do (
        for /f "delims=0123456789abcdefghijklmnopqrstuvwxyz" %%b in ("%%a") do (
            if %%b==W (
                echo %%a,anger
            ) else if %%b==F (
                echo %%a,happy
            ) else if %%b==N (
                echo %%a,neutral
            )
        )
    )) > wavFileOut.txt