Yogesh123 Topic Starter
Posts: 57
|
 |
« on: November 17, 2009, 05:45:09 AM » |
|
Dear Experts,
How to do this,
if token no 5 in abc.txt is LEQ 25, do echo %%i %%j %%k %%l %%m %%n %%o of abc.txt to output.txt
this is what i have tried cd\ d: for /f "tokens=5" %%i in (abc.txt) do set LD=%%i if %LD% LEQ 25 (echo %%i %%j %%k %%l %%m %%n %%o>> output.txt ) else ( echo Noresult found ) pause
abc.txt has following record, abc.tre 0 W131738 qwe 16 2009 sfsdf.sdfsdf 0 W131455 qwe 27 2009 fsdf.rty 0 W7F0BCU182 qwe 30 2009 qw.qwe 2 w4059 qwe 15 2009 wsx.rfv 2 W0132017 qwe 12 2009 xdr.cft 0 W0132017 qwe 11 2009 tgb.ikm 2 W0131738 qwe 31 2009 xdr.cft 0 W0132017 qwe 25 2009
Output.txt should have, (records where the 5th coloumn value is LEQ 25 ) abc.tre 0 W131738 qwe 16 2009 qw.qwe 2 w4059 qwe 15 2009 wsx.rfv 2 W0132017 qwe 12 2009 xdr.cft 0 W0132017 qwe 11 2009 xdr.cft 0 W0132017 qwe 25 2009
but i am getting following result in output.txt %i %j %k %l %m %n %o pls advise.
|
|
|
|
|
gh0std0g74
Thanked: 37 Posts: 590
|
 |
« Reply #1 on: November 17, 2009, 05:52:35 AM » |
|
you are missing a bracket of the for loop
|
|
|
|
Yogesh123 Topic Starter
Posts: 57
|
 |
« Reply #2 on: November 17, 2009, 06:01:27 AM » |
|
Dear gh0std0g74, are you talking about for bracket, i have tried by this also , but not working cd\ d: for /f "tokens=5" %%i in (abc.txt) do ( set LD=%%i if %LD% LEQ 25 (echo %%i %%j %%k %%l %%m %%n %%o>> output.txt ) else ( echo Noresult found ) ) pause
|
|
|
|
|
|
|
Yogesh123 Topic Starter
Posts: 57
|
 |
« Reply #4 on: November 17, 2009, 09:21:41 AM » |
|
Dear Salmon Trout, seems to be not working properly, the result i got in output.txt is as follows, 16 %j %k %l %m %n %o 27 %j %k %l %m %n %o 30 %j %k %l %m %n %o 15 %j %k %l %m %n %o 12 %j %k %l %m %n %o 11 %j %k %l %m %n %o 31 %j %k %l %m %n %o 25 %j %k %l %m %n %o
the result in output.txt should be (the output.txt should omit the record, where in the 5th token of abc.txt is greater than 25) abc.tre 0 W131738 qwe 16 2009 qw.qwe 2 w4059 qwe 15 2009 wsx.rfv 2 W0132017 qwe 12 2009 xdr.cft 0 W0132017 qwe 11 2009 xdr.cft 0 W0132017 qwe 25 2009
|
|
|
|
|
|
|
Yogesh123 Topic Starter
Posts: 57
|
 |
« Reply #6 on: November 17, 2009, 09:57:57 AM » |
|
Thanx Salmon Trout, Condition checking part is done, but values of %%j %%k %%l %%m %%n are not displaying
result of output.txt i got is, 16 %j %k %l %m %n %o 15 %j %k %l %m %n %o 12 %j %k %l %m %n %o 11 %j %k %l %m %n %o
please advise.
|
|
|
|
|
|
|
Yogesh123 Topic Starter
Posts: 57
|
 |
« Reply #8 on: November 17, 2009, 10:28:34 AM » |
|
Thanks a lot Salmon Trout, followed ur advise,  , had small break and cleaned my glasses. its working great.
|
|
|
|
|
billrich Guest
|
 |
« Reply #9 on: November 17, 2009, 11:51:06 AM » |
|
C:\batch>cat yo.bat
@echo off rem for /f "delims=" %%a in (abc5.txt) do ( rem echo %%a rem pause )
setlocal enabledelayedexpansion for /f "tokens=1-7" %%i in (abc5.txt) do ( set LD=%%m if !LD! LEQ 25 ( echo %%i %%j %%k %%l %%m %%n %%o ) else ( echo. echo No result found echo !LD! is greater than 25 echo %%i %%j %%k %%l %%m %%n %%o echo. ) )
) OUTPUT:
C:\batch>yo.bat abc.tre 0 W131738 Nov 16 12:00:57 2009 sfsdf.sdfsdf 0 W131455 Nov 16 10:02:11 2009 fsdf.rty 0 W7F0BCU182 Nov 16 11:02:12 2009 qw.qwe 2 w4059 Nov 16 09:05:38 2009
No result found 26 is greater than 25 wsx.rfv 2 W0132017 Nov 26 05:06:13 2009
xdr.cft 0 W0132017 Nov 16 07:06:33 2009 tgb.ikm 2 W0131738 Nov 16 12:15:01 2009 C:\batch>
|
|
|
|
|
billrich Guest
|
 |
« Reply #10 on: November 17, 2009, 12:48:17 PM » |
|
C:\batch>cat yo2.bat
@echo off rem for /f "delims=" %%a in (abc5.txt) do ( rem echo %%a rem pause )
rem setlocal enabledelayedexpansion for /f "tokens=1-7" %%i in (abc5.txt) do ( set LD=%%m if %%m LEQ 25 ( echo %%i %%j %%k %%l %%m %%n %%o ) else ( echo. echo No result found echo %%m is greater than 25 echo %%i %%j %%k %%l %%m %%n %%o echo. ) )
) OUTPUT:
C:\batch>yo2.bat abc.tre 0 W131738 Nov 16 12:00:57 2009 sfsdf.sdfsdf 0 W131455 Nov 16 10:02:11 2009 fsdf.rty 0 W7F0BCU182 Nov 16 11:02:12 2009 qw.qwe 2 w4059 Nov 16 09:05:38 2009
No result found 26 is greater than 25 wsx.rfv 2 W0132017 Nov 26 05:06:13 2009
xdr.cft 0 W0132017 Nov 16 07:06:33 2009 tgb.ikm 2 W0131738 Nov 16 12:15:01 2009 C:\batch>
|
|
|
|
|
gh0std0g74
Thanked: 37 Posts: 590
|
 |
« Reply #11 on: November 17, 2009, 01:18:16 PM » |
|
@OP, are you sure this is a foolproof method to check for date just by comparing 1 or 2 token??
|
|
|
|
|
|
billrich Guest
|
 |
« Reply #13 on: November 17, 2009, 02:25:46 PM » |
|
@OP, are you sure this is a foolproof method to check for date just by comparing 1 or 2 token??
There should be no problem as long as the input date is consistent. i.e.: The fifth field ( fifth token ) is the day of the month and the default delimiter is a space.
|
|
|
|
|
|
|