Hi,
I'm attempting to add a FOR Loop to a pre-existing cmd batch that I have, and am very confused by the stuff I've found on the web by way of documentation regarding using for loops.
Here is my old code: -
@echo on
-
echo Now processing: %1
-
@echo off
-
-
if !%1==! goto ERROR
-
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 1 /p" > %2____1_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 10001 /p" > %210001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 20001 /p" > %220001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 30001 /p" > %230001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 40001 /p" > %240001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 50001 /p" > %250001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 60001 /p" > %260001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 70001 /p" > %270001_nodin
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 80001 /p" > %280001_nodin
-
-
%1\util\sed -n -e "/time/p" %2nodout | %1\util\sed -n -e "$!N; /^\(.*\)\n\1$/!P; D" > %2time_nodin
-
-
REM %1 = Current Working Directory
-
REM %2 = ".\shake_01\"
-
REM Format would be do_a_shake2.cmd . .\shake_01\
-
-
goto EXIT0
-
:ERROR
-
@echo on
-
echo Usage: do_a_node .\shake_01\
-
echo Creates: X+1 bottle datafiles for each shake and a time datafile
-
echo
-
:EXIT0
-
Here is the FOR Loop I intend to add: -
-
FOR /L %%G IN (1,1,%3) DO %1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ 10001 /p" > %210001_nodin
-
I've taken one of the calls to the sed and inserted it where the example had "[Commands]", is this the correct way to format it? If there is a new argument "%3 (which is the number of times I want to do this loop, instead of the standard 8 times in the old code (above), would it work to substitute that argument, in the sed statement in the two places where there are mention to the # (at the beginning of the stuff in the strings #0001, where it currently is set to 1,2,3...7,8 (I bolded the numbers in the above codes, which would be substituted with the count variable).
Or would it be better to save the sed call into a new cmd file and call that from the FOR loop passing in the appropriate # for the call? (FYI, I have the windows sed utility, if your wondering how I'm calling sed from a windows cmd file...)
Examples and explanations would be much appreciated.
Thanks,
Sitko.
2 7061
<please delete me....thanks>
Just to tell you how I figured this out. I created 3 scripts which were:
Main Code. -
' VBScript source code
-
Dim WshShell
-
Dim CurWrkDir
-
Dim fso, f, f1, s, sf
-
Dim MyPos
-
Dim FolderName
-
Dim CmdName
-
Dim oExec
-
Dim vArg, aArgs(), iCount
-
Dim NumOfBottles
-
-
If WScript.Arguments.Count > 1 then
-
WScript.Echo "Too many arguments"
-
WScript.Quit
-
End If
-
If WScript.Arguments.Count = 0 Then
-
NumOfBottles = 6
-
Else
-
ReDim aArgs(wscript.Arguments.Count -1)
-
For iCount = 0 to WScript.Arguments.Count -1
-
aArgs(iCount) = WScript.Arguments(iCount)
-
NumOfBottles = aArgs(iCount)
-
Next
-
End If
-
-
Set WshShell = WScript.CreateObject("WScript.Shell")
-
CurWrkDir = WshShell.CurrentDirectory
-
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
Set f = fso.GetFolder(CurWrkDir)
-
Set sf = f.SubFolders
-
For Each f1 in sf
-
FolderName = f1.name
-
MyPos = InStr(1, FolderName, "shake", 1)
-
if MyPos <> 0 then
-
CmdName = "do_a_Shake.cmd " & CurWrkDir & " " & f1.path & "\ "
-
& NumOfBottles
-
Set oExec = WshShell.Exec(CmdName)
-
Do While oExec.Status = 0
-
WScript.Sleep 100
-
Loop
-
end if
-
Next
-
Do_A_Shake.cmd, has basically just this FOR loop along with a couple other unrelevant codes...The FOR statement, I ended up using was: -
FOR /L %%G IN (1,1,%3) DO DoSed %1 %2 %%G
-
and as I couldn't figure out haw to call the command with the FOR statement, I moved it to a new cmd file and called (DoSed.cmd) from the previous code. -
@echo off
-
%1\util\sed "/z-rot acc/,/n o d a l/d;/Center/d;/Bottle/d;/n o d a l/d" %2nodout | %1\util\sed -n "/ %30001 /p" > %2%30001_nodin
-
Any other improvements you can offer, would be appreciate, or maybe an explaination of what the vArg variable in the first code snippet is for (I got the argument code off the web, but don't see a call to it anywhere...
In the end, it works...so I guess thats the most important thing...
Thanks,
Sitko.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken Miller |
last post by:
Hi all. I'm fairly new to programming, and have started using visual
basic.net, just found this place, so hope someone can help as I'm a little
stuck :)
I'm trying to write a small front end to...
|
by: none |
last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs
to be modified. The problem I have is this:
The SysAdmin uses this shell in place of Explorer, so there is no
taskbar. When...
|
by: Daven Nair |
last post by:
Hi,
I would like to know if Python supports codes similar to shell scripts:
count=`ps -ef|grep "pattern"|wc -l`
for count in `echo $count`
do
done
fi
|
by: Francesco |
last post by:
Hello Pythonnian's
(sorry for crossposting)
I have written on the base of Miro Rajic a (still) small filemanager
in wxPython.
Now I want to add (for Windows XP) a explorer shell context menu....
|
by: Juggler |
last post by:
Hi,
I have a shell script which takes three arguments, how can I call this
script from within a C++ program.
I am new to C++ programming and not sure how to accomplish this.
I tried using...
|
by: Javaman59 |
last post by:
Hi all,
I'm a Unix guy from way back, who's enjoying learning C# and Windows
programming. Overall, it's not such a difficult transition (as long as one
keeps an open mind :) ), but there is one...
|
by: Sin |
last post by:
Hello everyone,
I'm totally stumped at how little info I can find in MSDN or on the web
concerning this. It's almost as if only microsoft personel hold the key to
these secrets or something!!!
...
|
by: gjuro kladaric |
last post by:
it was not possible to make a shell extension from within VB2003, I believe
has anything changed since then, can I (easily) write a VB code that would
function as a shell extension
thank you
...
|
by: Mark |
last post by:
Hello,
What I need to know is if there is a better method to run/edit modules
on my pc.
I'm currently running the IDLE shell under Python 2.5, on Windows XP.
Every time I edit my .txt or .py...
|
by: Tom Gur |
last post by:
Hi,
It's seems that csh and tcsh acts a bit different when handling
special characters in quotes.
i.e: if i'll supply my program with the following arguments: -winpath
"c:\\temp\\"
tcsh will...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |