sasi
sasi

Reputation: 364

Batch script printing only last line of file

I am trying to get some text from a file and displaying it. When I print the values I am getting only last line of file two times.

for /F %A in (E:\auto_s3\fol.txt) do (
setlocal
set m=%A 
setlocal
set k=%m:~1,-1%
echo %k%)

fol.txt

//LogShare/sapbatch01/audit-sapbatch01
//LogShare/sapdial18/audit-sapdial18

Upvotes: 1

Views: 2231

Answers (1)

user7818749
user7818749

Reputation:

Setting single character variables are ugly. Also, you need enabledelayedexpansion

@echo off
setlocal enabledelayedexpansion
for /F %A in (E:\auto_s3\fol.txt) do (
   set mvar=%A 
   set kvar=!mvar:~1,-1!
   echo !kvar!
)

To run it in an actual batch file, add a % This:

@echo off
setlocal enabledelayedexpansion
for /F %%A in (E:\auto_s3\fol.txt) do (
   set mvar=%%A 
   set kvar=!mvar:~1,-1!
   echo !kvar!
)

Note! as for the other script to get previous day and day before, here is a link to the answer I created on something similar.

Upvotes: 2

Related Questions