bdecker
bdecker

Reputation: 1

force a carriage return in a batch

Thanks in advance

I have a batch file that reads 1500+ files, finds a specific line of text, then inserts four separate strings. But I need each string on its own line. Below is a copy of working code. "Working" except all four strings are on one line. I need four lines.

@echo off      
setlocal EnableExtensions EnableDelayedExpansion

FOR %%G IN (E:\SweepstakesNinja\sweepstakesninja\sweepstakesfilesCustomSubmissions\) DO DEL /Q %%G

pause

set SrcFolder=E:\SweepstakesNinja\sweepstakesninja\sweepstakesfiles
set DstFolder=E:\SweepstakesNinja\sweepstakesninja\sweepstakesfilesCustomSubmissions
set "echotext0=[**]details==>>mainsweepstakessubmissiontype||==||3"
set "echotext1=[**]details==>>prizevalue||==||"
set "echotext2=[**]details==>>startdate||==||2010.01.01"
set "echotext3=[**]details==>>mainid||==||0"

for %%a in ("%SrcFolder%\*.txt") do (
  for /f "usebackq delims=" %%h in ("%%~a") do (
    echo.%%h 
         if "%%h" equ "[**]details==>>countries||==||"            (echo !echotext0!!echotext1!!echotext2!!echotext3!) ^
    else if "%%h" equ "[**]details==>>countries||==||USA"         (echo !echotext0!!echotext1!!echotext2!!echotext3!) ^
    else if "%%h" equ "[**]details==>>countries||==||USA, Canada" (echo !echotext0!!echotext1!!echotext2!!echotext3!) ^
    else if "%%h" equ "[**]details==>>countries||==||USA,Canada"  (echo !echotext0!!echotext1!!echotext2!!echotext3!)
  )
) > "%DstFolder%\%%~nxa"

echo DONE

BD

Upvotes: 0

Views: 2138

Answers (1)

Compo
Compo

Reputation: 38589

Your code is specifically echoing only one line, to echo four add three more echo's. Change each instance of

(echo !echotext0!!echotext1!!echotext2!!echotext3!)

to

(echo !echotext0!&echo !echotext1!&echo !echotext2!&echo !echotext3!)

As you credited the wrong person in comments, I've decided to post my comment to be marked as an answer appropriately.

Upvotes: 1

Related Questions