Showing posts with label Batch. Show all posts
Showing posts with label Batch. Show all posts

Monday, April 30, 2007

Windows Grep Functionality

Windows has a find command which can be used in batch files and in the cmd prompt to search for strings in files or in output. My most recent discoveries is the type command and using find in a grep like functionality.

Say you have a text file with lines of code/numbers/names/etc and you'd like to see the line which has the text you are looking for. You'd type the following:

> type file.txt | find /I "something"

Replace file.txt with the filename you want to search in, and something with the text you are looking for.

The /I switch is to make the search case insensitive. Type find /? at the command prompt for more options.

Here is an example. If you want to find out if your python bin directory is in your path you would type:

> SET | find /I "python"
results:
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Common Files\GTK\2.0\bin;C:\bin;C:\Python24;C:\Program Files\Windows Script Encoder;C:\Program Files\7-Zip
Note: The SET command prints out your environment variables. Much like env does on *ix.

Follow here, for more Useful Windows command prompt commands.

Sunday, April 15, 2007

Publishing Hiccup

To my surprise I logged in this morning to check on my application since I scheduled it to run a little after midnight. I found out it ran, but nothing happened! I went through the batch file, only to find my debug code on.. (the echo before cscript command) *sigh* Its good I arrived to work early. I re-ran the applications. Which are proving to be quite hefty on the system but definitly worth the overhead.

Wednesday, April 11, 2007

Multi Variable Batch

This is a great example for reading lines through a regular batch file and processing the input at tokens.

Lets say for example you have a file with the following input:

user1 homedir1
user1 homedir2


etc

If you want to, you could add this to your batch file;

for /f "tokens=1*" %%i in (filename.txt) do @echo %%j\%%i


Notice that %%j was not defined, but is automatically assigned a value alphabetically. The output will look something like;

homedir1\user1
homedir2\user2