0
03a01Fa.wav
03a01Nc.wav
03a01Wa.wav

I have this text file

by using batch file i want to appent "anger" if the letter in caps is W, if the letter is F then "happy", N for "neutral". is it possible to do ?

i want it like this

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

Thanks in advance, looking forward to a solution.

user3388785
  • 71
  • 1
  • 2

4 Answers4

1
@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]!
)

You may review the array management in Batch files at this post.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
1

Another way using FIND :

@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)

If you need the output in a file (output.txt) :

@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
SachaDee
  • 9,245
  • 3
  • 23
  • 33
0
@echo off
setlocal enabledelayedexpansion
(for /f %%i in (t.t) do (
 set a=%%i
 set a=!a:~5,1!
 if !a!==F echo %%i,happy
 if !a!==N echo %%i,neutral
 if !a!==W echo %%i,angry
))>o.t
Stephan
  • 53,940
  • 10
  • 58
  • 91
0
@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
MC ND
  • 69,615
  • 8
  • 84
  • 126