|
List Info
Thread: Controlling script execution without environment variables based on file content
|
|
| Controlling script execution without
environment variables based on file
content |
  United States |
2008-05-15 12:35:45 |
Need to peek in a file, and based on what you see,
conditionally
execute a subroutine in an XP batch file? Tired of trying to
figure
out how to stuff a value into an environment variable?
Instead, use
GNU grep from gnuwin32.sourceforge.net and try:
grep CONDITION filename && goto JUST-DO-IT
rem DON'T DO IT - put commands here to perform if condition
not met
goto OVER-IT
:JUST-DO-IT
put commands here to perform if condition met
:OVER-IT
The portion of the first command line after the &&
only executes if
the grep was successful. If grep found what you were looking
for, the
script branches to JUST-DO-IT. If grep did not find what you
were
looking for, the next line executes, and all lines below it,
until you
hit the second goto which sends you over the the JUST-DO-IT
branch,
and rejoins the script at OVER-IT.
|
|
| Re: Controlling script execution without
environment variables based on file
content |
  United States |
2008-05-16 10:42:17 |
> John Bartley K7AAY wrote:
> > Need to peek in a file, and based on what you see,
conditionally
> > execute a subroutine in an XP batch file? Tired of
trying to figure
> > out how to stuff a value into an environment
variable? Instead, use
> > GNU grep from gnuwin32.sourceforge.net and try:
> >
> > grep CONDITION filename && goto
JUST-DO-IT
> > rem DON'T DO IT - put commands here to perform if
condition not met
> > goto OVER-IT
> > :JUST-DO-IT
> > put commands here to perform if condition met
> > :OVER-IT
>
> > The portion of the first command line after the
&& only executes if
> > the grep was successful. If grep found what you
were looking for, the
> > script branches to JUST-DO-IT. If grep did not
find what you were
> > looking for, the next line executes, and all lines
below it, until you
> > hit the second goto which sends you over the the
JUST-DO-IT branch,
> > and rejoins the script at OVER-IT.
On May 16, 1:43 am, Manuel Collado <m.coll... see.signature.es>
escribió:
> The script can be rewritten as:
>
> grep -q CONDITION filename
> if not ERRORLEVEL 1 (
> put commands here to perform if CONDITION found
> ) else (
> put commands here to perform if CONDITION not
found
> )
>
> Yes, this is for Windows XP.
>
> Hope this helps.
> --
> Manuel Collado -http://lml.ls.fi.up
m.es/~mcollado
Gracias, Sr. Collado, appreciate learning a new way to do
it. I tend
to write tersely, and your method is likely easier for some
to read.
As for everyone else, well, I have been asking a lot of
questions
recently, and since I found a solution for a problem I was
thinking
about asking for help with, I thought I would post my
solution to my
problem, hoping it helps someone else.
|
|
| Re: Controlling script execution without
environment variables based on |
  United States |
2008-05-16 10:46:30 |
> John Bartley K7AAY (john.bart... gmail.com) wrote:
> > Need to peek in a file, and based on what you see,
conditionally
> > execute a subroutine in an XP batch file? Tired of
trying to figure
> > out how to stuff a value into an environment
variable? Instead, use
> > GNU grep from gnuwin32.sourceforge.net and try:
> > grep CONDITION filename && goto
JUST-DO-IT
> > rem DON'T DO IT - put commands here to perform if
condition not met
> > goto OVER-IT
> > :JUST-DO-IT
> > put commands here to perform if condition met
> > :OVER-IT
> > The portion of the first command line after the
&& only executes if
> > the grep was successful. If grep found what you
were looking for, the
> > script branches to JUST-DO-IT. If grep did not
find what you were
> > looking for, the next line executes, and all lines
below it, until you
> > hit the second goto which sends you over the the
JUST-DO-IT branch,
> > and rejoins the script at OVER-IT.
On May 16, 7:32 am, ak... chebucto.ns.ca (Richard
Bonner) replied:
> *** I have not used grep.
Dude, you HAVE to go to gnuwin32.sourceforge.net - the core
utilities
and text utilities there, alongside the GNU version of grep
for XP,
will make your day. The XMLstarlet program is just icing on
the
Timmie's doughnut, and has save my back bacon a considerable
number of
times.
> Is it just a text string for which you are looking?
In a 17GB file. grep handled it nicely, so I used grep
instead of
find.
> If so:
>
> TYPE filename.ext | FIND "string"
> IF ERRORLEVEL 1 GOTO JUST-DO-IT
>
> ON'T-DO-
IT
> (put commands here to perform if string not found)
> GOTO OVER-IT
>
> :JUST-DO-IT
> (put commands here to perform if string is found)
>
> :OVER-IT
>
> Richard Bonnerhttp://www.chebuct
o.ca/~ak621/DOS/
|
|
| Re: Controlling script execution without
environment variables based on |
  United States |
2008-05-16 09:32:28 |
John Bartley K7AAY (john.bartley gmail.com) wrote:
> Need to peek in a file, and based on what you see,
conditionally
> execute a subroutine in an XP batch file? Tired of
trying to figure
> out how to stuff a value into an environment variable?
Instead, use
> GNU grep from gnuwin32.sourceforge.net and try:
> grep CONDITION filename && goto JUST-DO-IT
> rem DON'T DO IT - put commands here to perform if
condition not met
> goto OVER-IT
> :JUST-DO-IT
> put commands here to perform if condition met
> :OVER-IT
> The portion of the first command line after the
&& only executes if
> the grep was successful. If grep found what you were
looking for, the
> script branches to JUST-DO-IT. If grep did not find
what you were
> looking for, the next line executes, and all lines
below it, until you
> hit the second goto which sends you over the the
JUST-DO-IT branch,
> and rejoins the script at OVER-IT.
*** I have not used grep. Is it just a text string for
which you are
looking? If so:
TYPE filename.ext | FIND "string"
IF ERRORLEVEL 1 GOTO JUST-DO-IT
ON'T-DO-
IT
(put commands here to perform if string not found)
GOTO OVER-IT
:JUST-DO-IT
(put commands here to perform if string is found)
:OVER-IT
Richard Bonner
http://www.chebuct
o.ca/~ak621/DOS/
|
|
| Re: Controlling script execution without
environment variables based on file
content |
  United States |
2008-05-16 03:43:36 |
John Bartley K7AAY escribió:
> Need to peek in a file, and based on what you see,
conditionally
> execute a subroutine in an XP batch file? Tired of
trying to figure
> out how to stuff a value into an environment variable?
Instead, use
> GNU grep from gnuwin32.sourceforge.net and try:
>
> grep CONDITION filename && goto JUST-DO-IT
> rem DON'T DO IT - put commands here to perform if
condition not met
> goto OVER-IT
> :JUST-DO-IT
> put commands here to perform if condition met
> :OVER-IT
>
> The portion of the first command line after the
&& only executes if
> the grep was successful. If grep found what you were
looking for, the
> script branches to JUST-DO-IT. If grep did not find
what you were
> looking for, the next line executes, and all lines
below it, until you
> hit the second goto which sends you over the the
JUST-DO-IT branch,
> and rejoins the script at OVER-IT.
The script can be rewritten as:
grep -q CONDITION filename
if not ERRORLEVEL 1 (
put commands here to perform if CONDITION found
) else (
put commands here to perform if CONDITION not found
)
Yes, this is for Windows XP.
Hope this helps.
--
Manuel Collado - http://lml.ls.fi.up
m.es/~mcollado
|
|
[1-5]
|
|