Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:49 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : UNIX-like commands: cat dir grep more

Author Message
rave
Newbie

Joined: 24/02/2018
Location: United States
Posts: 28
Posted: 03:35am 22 Apr 2018
Copy link to clipboard 
Print this post

Hi all,

I've uploaded my UNIX-like "implied RUN commands" to FruitOfTheShed

These commands are:

cat catenate files to output
dir list files
grep search files using a pattern or string
more file pager and hexdump utility

These commands support the following useful command-line features:

- File and directory name globbing with * and ?
- Paths can be separated with \ as usual or with /
- Input can be redirected with < FILE
- Output can be redirected with > FILE or >> FILE (append)

This works thanks to the power of MMBasic 4.5. Geoff did a great job and for MMBasic.

For example:

- Display and page through all .bas files in the project directory and its subdirectories (hit key SPACE/ENTER/ESC while viewing):
more project/*.bas project/*/*.bas


- Hexdump all .bmp files located in B:\images:
more -x B:\images\*.bmp


- Search and display the lines with line numbers of .bas files in the project directory that have the text "Usage" at the start of the line:
grep -n "^Usage:" project/*.bas


A driver program WALKDIRS.BAS is included in MMUNIX-v2.zip to implement your own UNIX-like commands. The driver program performs de-globbing and sets up file redirects. This way you only have to add a few command-related subs to perform actions on files/directories .

I've "stolen" a bit of beautiful code written by Rob Pike for regex matching with my grep implementation, but I rewrote it in MMBasic and added the [] ? + operators to make it more useful.

Enjoy!

- Rob
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 02:50pm 22 Apr 2018
Copy link to clipboard 
Print this post

Hi Rob!
Congratulation! Good job!
GREP and REGEX are a must have.
I will try later.
Kind regards
Michael


causality ≠ correlation ≠ coincidence
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025