Are you interested in combating drudgery?

In your job do you have pretty simple repetitive tasks to do?
Are they jobs that involve doing the same thing to every file in a directory?
Do you end up with RSI (no need to answer this one … just there for drama)?
Are you sheepish to ask your office’s IT people?
Are you a self-professed non-programmer, but have a tiny little nerdy molecule here or there?
If your answer to the questions above is “what are you on about?” … read on.

My message is, don’t ditch the command line, whether you are on Windows, Linux or Mac OS X.

Did you know, regarding Windows and the Command Prompt window that:

You can issue a pretty simple command like:

domyjob.bat *.*ml

and with the tiniest bit of perseverance you can save yourself heaps of time by learning about MS-DOS scripting.

Let’s say you do the “Hello World” of MS-DOS scripting:

a) Use Notepad to create a file that contains:

echo “Hello World”
pause

… and File->Save As … helloworld.bat (on the path (if you are advanced) or on C: (root directory of C:) if you are allowed or “My Documents” if you have reached this)

b) Get to Command Prompt window via that bottom left Window icon->Accessories->Command Prompt (or by some icon you have) or by going CMD in the Run box

c) If you are a “My Documents” user maybe use Windows Explorer, go to My Documents and double click helloworld.bat icon, else, type
helloworld.bat

… did you get a warm glow?!

…………

Okay, let’s talk about:

domyjob.bat *.*ml

Use Notepad to create:

:domore
if TRICK%1==TRICK goto nomore
TYPE %1 | MORE
SHIFT
goto domore
:nomore
pause

… and Save As … domyjob.bat (on the path somewhere … huh? see DOS starter tips and is like homework for next week … where we change TYPE %1 | MORE into something much more interesting)

At command prompt type in (where the *.*ml is just a suggestion … maybe *.txt or *.csv etcetera) … but be in the directory where the data is … then type:

domyjob.bat *.*ml

… do you see the possibilities? Maybe we’ll come back with more stuff next week?!

Well … here we are back again on 4/3/2013 … on the same theme … look at this *.bat version of Unix/Linux fgrep … well, is same as find you all say … but am going to show you some programmatic alternatives to the “find” of the picture below … perhaps PHP … perhaps C … fact is, though, that many things are possible in this Open Source world … and want to show you some in the continuing saga of this article …

fgrep in *.bat

Well … here we are back again on 5/3/2013 … on the same theme … look at the PHP command line (Windows Command Prompt) ideas below … but please read Great PHP Advice beforehand …

  • Is PHP installed? … mine is EasyPHP 12.1 from http://www.easyphp.org/
  • For me … was installed … but dumb old me … didn’t know path to it … if you are dumb like me … go DIR C:PHP.exe /s … remember, note result
  • Add this to PATH environment variable … am showing you Command Prompt way below but would prefer you to do it using Windows Control Panel->System->System and Security->System->Advanced system settings-> Environment Variables …->Highlight Path->Edit (append to end results as above … have you forgotten already?)
  • Add .PHP to PATHEXT as shown, but better, as above, using Control Panel technique
  • Do assoc command shown as an administrator
  • Do ftype command shown as an administrator
  • Here’s where I hope not to lose you … you need to go REGEDIT in that administrator Command Prompt window and fill out the register to make it look as below or as on Great PHP Advice from http://php.net/manual/en/install.windows.commandline.php … soRRRyyyy
  • Restart … how many more have I lost? “Lots, dummy, they’re rebooting!” When you come back you should be able to run your PHP from command line
  • Back again … great … as you come back you should be able to run your PHP from command line, as shown below … yes, Hello World is boring … but PHP is endlessly brilliant at doing more than Hello World … patience until tomorrow!

PHP command line

Well … here we are back again on 6/3/2013 … on the same theme … look at the PHP command line (Windows Command Prompt) ideas below … this software runs through a filespec of interest replacing one string with another (if you are really good with text editor something like UltraEdit (or TextWrangler in Mac OS X) you would know the issue) … there was a bit of a setback that made the job far more complex than you may find it … the command line parameters didn’t get recognized in PHP, for me … am still looking into it … but got my str_replace.bat to do more of the clever stuff to get around it … imagine the PHP code without the call to secondchoice() and this is the scenario where PHP is recognizing all of the command line, as it should (and am hoping, one day it will, for me) … you can download software (where you will have to rename yourself (getting rid of _GETME suffix) at str_replace.php and str_replace.bat … but, besides all that … what you have here is the mechanism for piping … the way in MS-DOS and Linux/Unix whereby you start with file(s) and pipe it/them through processes to get output file(s)/report(s) … eg. DIR | more … the | is an indicator that “piping” is happening … “piping” operations are great, in that you can process a lot of data at one execution, and you are, usually, not asked for further input from the keyboard or mouse … if you like this idea then get good with > for “write/clobber” and >> for “append” and with < for “read from” …

PHP command line primer

Yes, it is true that this will not help with proprietary formats like Word (please do not even try it with any file that is not readable in your mother tongue), but Word, for example, can be converted into HTML, and it may help with that. It starts you thinking about the processes, and is there an easier way. Supposing you have to use Word, but the thing that takes you the longest is some thing in the middle which you can call a “text blob” (for which you can use such PHP methods as above or as below (as of 7/3/2013) with C methods) … have you ever thought about different ways to tackle the problems, even for the purposes of brightening your workday?!

Well … here we are back again on 7/3/2013 … (rabbiting) on (with) the same theme … look at the C command line (Windows Command Prompt) ideas below … this software runs through a filespec of interest replacing one string with another (if you are really good with text editor something like UltraEdit (or TextWrangler in Mac OS X) you would know the issue) … used Digital Mars C compiler (which is free! … yay! … and thanks) … for relatively straightforward jobs all that is needed on a default install is to do all your work in C:dmbin and write your C (eg. str_replace.c) then go … dmc str_replace.c … voila! you get str_replace.exe (if you have eaten your greens) … you can download software (where you will have to rename yourself (getting rid of _GETME_ suffix) at str_replace.c and str_replace.bat … but, besides all that … what you have here is the mechanism for piping … the way in MS-DOS and Linux/Unix whereby you start with file(s) and pipe it/them through processes to get output file(s)/report(s) … eg. DIR | more … the | is an indicator that “piping” is happening … “piping” operations are great, in that you can process a lot of data at one execution, and you are, usually, not asked for further input from the keyboard or mouse … if you like this idea then get good with > for “write/clobber” and >> for “append” and with < for “read from” …

C command line primer

Well … here we are back again on 8/3/2013 … (rabbiting) on (and on) (with) the same theme … look at the Unix/Linux shell ideas below … Unix and then Linux operating systems are the (spiritual) home of “piping” … it is almost like they were invented for it … this software runs through a filespec of interest replacing one string with another … helpful Unix/Linux shell script advice … for relatively straightforward jobs all that is needed is to write your shell script (this job did not need any compiled code at all) … ./str_replace.sh … runs from the command line … you can download software (where you will have to rename yourself (getting rid of _GETME suffix) at str_replace.sh … but, besides all that … what you have here is the mechanism for piping … the way in MS-DOS and Linux/Unix whereby you start with file(s) and pipe it/them through processes to get output file(s)/report(s) … eg. DIR | more … the | is an indicator that “piping” is happening … “piping” operations are great, in that you can process a lot of data at one execution, and you are, usually, not asked for further input from the keyboard or mouse … if you like this idea then get good with > for “write/clobber” and >> for “append” and with < for “read from” …

Unix and Linux str_replace.sh

Rabbitting on …

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *