简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM