Computing.Net > Forums > Disk Operating System > Need help in For /f command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need help in For /f command

Reply to Message Icon

Name: rkayasth
Date: March 30, 2009 at 21:51:51 Pacific
OS: Windows XP
CPU/Ram: WinXP SP3 / 1GB
Subcategory: Software Problems
Comment:

I am using the following command in a batch file
------------------------
for /F "skip=8" %%a IN (E:\tempfile.log | findstr /I ERROR) do (goto :ERR2)
Del E:\tempfile.log /q
--------------
What I need is to skip the 1st 8 lines (using skip=8) in the E:\tempfile.log and then find the word "Error" / ERROR in the 9th line (ALWAYS), and if you find this word, display error message in :ERR2.
But this is never executed, means it doesnt goto :ERR2.
Whats the problem in this command?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 30, 2009 at 22:54:17 Pacific
Reply:

[1] XP is not DOS.

[2] I don't see the label :ERR2

[3] If it boils down to: 'check line nine for ERROR', try this:

=========================
:: chk line 9 for ERROR

@echo off & setLocal EnableDelayedExpansion

set N=

for /f "tokens=* delims=" %%a in (E:\tempfile.log) do (
set /a N+=1
if !N! equ 9 (
echo %%a | find /i "error" > nul
if !errorlevel! equ 0 echo here's where we GOTO
)
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: rkayasth
Date: March 30, 2009 at 23:07:47 Pacific
Reply:

Mechanix,
Sorry for the goofup....
actually I am trying to get this o/p since last 3 days, so quite exhausted after all this tries.
I will try your solution, and reply back
Thanks,
Ravin


0

Response Number 3
Name: rkayasth
Date: March 31, 2009 at 00:25:24 Pacific
Reply:

I need to expand my code to search for multiple words and then throw error based on the string found
i.e if the string is "Error" goto :ERR2 or if string is "Missing" goto :ERR3
Mechanix, can we expand your code to handle the above situation?
Thanx,
Ravin


0

Response Number 4
Name: Mechanix2Go
Date: March 31, 2009 at 00:45:57 Pacific
Reply:

@echo off & setLocal EnableDelayedExpansion

set N=

for /f "tokens=* delims=" %%a in (E:\tempfile.log) do (
set /a N+=1
if !N! equ 9 (
echo %%a | find /i "error" > nul
if !errorlevel! equ 0 echo here's where we GOTO :ERR2
echo %%a | find /i "Missing" > nul
if !errorlevel! equ 0 echo here's where we GOTO :ERR3
)
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: rkayasth
Date: March 31, 2009 at 02:13:46 Pacific
Reply:

Hey Mechanix,
You are a gem of a person.
It works like a charm.
Just one last question.
I am having this command

"call windchill wt.load.loadfromfile -d c:\parts.xml > c:\logerror.log"

which may throw errors and logs it in the logfile, in which we are catching words and redirecting to goto :ERRn

but the command above is also getting displayed in my launch cmd also, which I dont want.

Pl help...
Thanx,
Ravin


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: March 31, 2009 at 03:35:39 Pacific
Reply:


Most commands send 'regular output' to stdout and errors to stderr.
Usually, writing to stdout and to stderr both 'put it on the screen'.
You can redirect bothe like this:

dir aa > dirlist 2> errlog

note: NO SPACE between 2 and >


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: rkayasth
Date: March 31, 2009 at 03:56:23 Pacific
Reply:

I do not want the following command to be executed on the screen, but the o/p or error of this command only in the logfile
"call windchill wt.load.loadfromfile -d c:\parts.xml > c:\logerror.log".

Mechanix, is it possible that we execute this command in a minimized window, redirect o/p (>logfile.log) and exit that window and back to main cmd?

Thanx,
Ravin


0

Response Number 8
Name: Mechanix2Go
Date: March 31, 2009 at 04:39:25 Pacific
Reply:

Is windchill a batch?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 9
Name: rkayasth
Date: March 31, 2009 at 23:10:12 Pacific
Reply:

Nope windchill is an exe, and then we are passing the parameters to it like
windchill wt.load.loadfromfile -d c:\parts.xml


0

Response Number 10
Name: Mechanix2Go
Date: April 1, 2009 at 02:29:42 Pacific
Reply:

start /min windchill wt.load.loadfromfile -d c:\parts.xml


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: rkayasth
Date: April 17, 2009 at 03:48:18 Pacific
Reply:

Hey mechanix,

I am redirecting the output to a log file,e.g.
echo +++Successfull ++++ >> c:\succcess.log

but I want the message to be prepended with a date/time stamp. e.g
04/18/2009 14:20 +++Successfull ++++

How do I get the above output?


0

Response Number 12
Name: Mechanix2Go
Date: April 21, 2009 at 00:07:18 Pacific
Reply:

echo %DATE% %TIME% +++Successfull ++++ >> c:\succcess.log


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Toshiba Sattelite Laptop ... Delete words in a text do...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Need help in For /f command

Need help saving hard drive info using dos commands www.computing.net/answers/dos/need-help-saving-hard-drive-info-using-dos-commands/4898.html

Dos Commands - Need Help ! www.computing.net/answers/dos/dos-commands-need-help-/8042.html

DOS problem with fonction FOR/F www.computing.net/answers/dos/dos-problem-with-fonction-forf/4420.html