Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
CluelessInSeattl(R)

Seattle, USA,
18.12.2012, 03:07
 

DOS utility to display 1st line of all files in directory? (Users)

I thought I once had a little DOS utility that would display a list of the first lines of all the text files in a specified directory.

I thought it was called DIRFIRST.

But I can't find it on any of my old floppies.

And when I Google "DIRFIRST" I get something completely different.

Could I be thinking of an old CP/M utility?

Do any of you know of such a utility that would work in MS-DOS 6.21?

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Doug(R)

E-mail

18.12.2012, 06:46

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

Perhaps more than you're looking for, but 4DOS alternative command shell (COMMAND.COM on steroids!) has the HEAD internal command. You can set the number of lines to display as a parameter. For example:

  head /n1 /v /p *.*

  "/n1" = display only the first line of each file
  "/v" = verbose (display file name(s) also)
  "/p" = pause after each screenful
  "*.*" = all files in current directory

You can also redirect the output to a file, for example:

  head /n1 /v *.* > filename

Get the latest (last?) 4DOS binaries here (4th link down):

  http://www.4dos.info/sources.htm

I couldn't work in DOS (where i do about 90% of my computing) without 4DOS.

- Doug B.

CluelessInSeattl(R)

Seattle, USA,
18.12.2012, 15:37
(edited by CluelessInSeattl, 18.12.2012, 20:03)

@ Doug
 

DOS utility to display 1st line of all files in directory?

> Perhaps more than you're looking for, but 4DOS alternative command shell
> (COMMAND.COM on steroids!) has the HEAD internal command.

Hi Doug!

Thanks for that speedy reply.

I'm hoping to one day graduate from MS-DOS to 4DOS, but for now I'm still stuck with MS-DOS 6.21.

[Edit: Hi again, Doug! When I first read your message I mistook "4DOS" for "FreeDOS," thinking that it was a replacement OS for MS-DOS. But just now while sorting messages in my inbox it dawned on me that you and written "4DOS" not "FreeDOS" so I Googled it and am excited by what I found. So the rest of my message below is off the mark. More to follow in another post.]

Due to the limitations imposed on me by disabling chronic illness I'm only able to spend an hour or so each day on my computer hobby, which at this point consists of trying to revive my old MS-DOS system. Sort of like an old guy whose hobby is restoring antique cars.

Years ago I did write a BASIC program that did what I'm looking for, but now I can't remember how to run it. Getting old is so entertaining.;-)

I could've sworn the name of that utility I used to use was called DIRFIRST. But so far none of my web searches have turned up a single reference to its existence.

Thanks again for your reply, I appreciate it,

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

myrkraverk(R)

18.12.2012, 20:09

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> > Perhaps more than you're looking for, but 4DOS alternative command shell
> > (COMMAND.COM on steroids!) has the HEAD internal command.

There might also be a HEAD program in the DJGPP suite. Depending on your needs, it might be worth checking out.

CluelessInSeattl(R)

Seattle, USA,
18.12.2012, 20:19

@ Doug
 

DOS utility to display 1st line of all files in directory?

> Perhaps more than you're looking for, but 4DOS alternative command shell
> (COMMAND.COM on steroids!) has the HEAD internal command. You can set the
> number of lines to display as a parameter.

Hi Doug!

I just looked up 4DOS and am intrigued by it. (I'm sure you'll wonder just which cave I've been living in all these decades).

I'd love to give it a try. But I have one big concern, and that is whether or not installing it would interfere with the execution of commands in my existing version of MS-DOS 6.21.

I depend on a large number of batch files, some of them rather complicated, for executing series of my most frequently used commands. I use a text editor with a built in macro language that allows me to call DOS commands and batch files from keyboard shortcuts from within the editor.

So, as you can probably imagine, it would be disappointing to me if I were to install 4DOS and then find that some of my most frequently used keyboard shortcuts had stopped working.

I no longer have the energy or stamina to monkey around with troubleshooting batch files that stop working. I created all of my batch files a decade or two ago, back when I still was able to spend hours and hours playing around on the computer. And it was so much fun, too! But now I have to work lying in bed, and even then I'm only good for about 45 minutes at a stretch.

So, how seamless do you think the transition from MS-DOS 6.21 to 4DOS would be for me?

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Rugxulo(R)

Homepage

Usono,
18.12.2012, 20:38

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> So, how seamless do you think the transition from MS-DOS 6.21 to 4DOS would
> be for me?

It's probably not worth it, then. 4DOS is only a COMMAND.COM replacement, a shell, "mostly" compatible (and adds a billion features for powerful scripting). You don't need it, but a lot of people prefer it for various reasons.

Anyways, here's a quick .BAT / .BAS combo I whipped up that should work verbatim in MS-DOS 6. (I assume this does what you want, otherwise you might have to use Sed, Awk, Edlin, or similar utility from wherever):


@echo off
REM Usage:  for %a in (*.txt) do call oneline.bat %a
set B1=%TEMP%.\oneline.bas
echo OPEN ENVIRON$("MYFILE") FOR INPUT AS #1 >%B1%
echo INPUT #1, line$ : PRINT line$ >>%B1%
echo CLOSE >>%B1%
echo SYSTEM >>%B1%
:begin
set MYFILE=%1
qbasic /run oneline.bas
for %%z in (MYFILE B1) do set %%z=

CluelessInSeattl(R)

Seattle, USA,
19.12.2012, 17:55

@ Rugxulo
 

DOS utility to display 1st line of all files in directory?

Thanks Rugxulo!

I'm going to take your batch file (see below) for a spin. Years ago I used to write a lot of batch files and had a heck of a lot of fun doing it. But that was a decade or more ago, so I'm rusty now. But your little batch file will give me something to play with and try to get back up to speed.

I don't have QBasic installed on my computer, so I figure I'll have to try to find it on an old floppy and install it before your file will work; right? (What do I need to do besides copying the QBasic files to a directory and adding the directory to my path?).

I'm only able to work a few minutes a day at my computers, so this may take me a day or two to get set up.

In the meantime, will your batch file look at the first line of all files in a directory, not just the ones with .txt extension? I use an alpha/numeric code for the three character file extensions as a way of tagging files.

Also, could I add a routine to your batch file so that it would sort the first lines into alpha/numeric order?

Will in Seattle
a.k.a. "Clueless"

> Anyways, here's a quick .BAT / .BAS combo I whipped up that should work
> verbatim in MS-DOS 6. (I assume this does what you want, otherwise you
> might have to use
> Sed,
> Awk,
> Edlin, or similar utility from wherever):
>
>
> @echo off
> REM Usage:  for %a in (*.txt) do call oneline.bat %a
> set B1=%TEMP%.\oneline.bas
> echo OPEN ENVIRON$("MYFILE") FOR INPUT AS #1 >%B1%
> echo INPUT #1, line$ : PRINT line$ >>%B1%
> echo CLOSE >>%B1%
> echo SYSTEM >>%B1%
> :begin
> set MYFILE=%1
> qbasic /run oneline.bas
> for %%z in (MYFILE B1) do set %%z=
>

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Rugxulo(R)

Homepage

Usono,
19.12.2012, 20:44
(edited by Rugxulo, 20.12.2012, 21:06)

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> Thanks Rugxulo!
>
> I'm going to take your batch file (see below) for a spin.
>
> I don't have QBasic installed on my computer, so I figure I'll have to try
> to find it on an old floppy and install it before your file will work;
> right? (What do I need to do besides copying the QBasic files to a
> directory and adding the directory to my path?).

I had thought QBASIC (QBASIC.EXE, QBASIC.HLP) was always installed. But maybe they only put it in "SUPP" (Supplement) add-on, I forget. That was my whole point, you wouldn't have to install anything extra! :-)

> In the meantime, will your batch file look at the first line of all
> files in a directory, not just the ones with .txt extension?

It probably won't work except for normal and readonly attribute files. But you can temporarily use Attrib to workaround that. If you need more than "*.txt", you'll have to change that to whatever else you want. If you need more than one extension, you may have to have another .BAT file "call" this one:


@echo off
REM ... There are tricker ways, but this will do in a pinch ...
for %%a in (*.aaa) do call oneline.bat %%a
for %%a in (*.bbb) do call oneline.bat %%a
for %%a in (*.ccc) do call oneline.bat %%a


> I use an
> alpha/numeric code for the three character file extensions as a way of
> tagging files.

In other words, "*.*" won't work because other non-text files are also present? As a silly workaround, you could probably "Attrib +H" those particular files, and then it would ignore them.

> Also, could I add a routine to your batch file so that it would sort the
> first lines into alpha/numeric order?

You mean sort the output of the ONELINE.BAT file? You may have to create an OUTER.BAT file first (as redirection within a nested FOR command doesn't always do what you'd expect):


@echo off
REM outer.bat
for %%a in (*.txt) do call oneline.bat %%a


Then do this:

C:\TMP> REM echo %%COMSPEC%% = %COMSPEC% (DOS 6 shell doesn't support env.var. expansion at cmdline)
C:\TMP> command /c outer.bat | sort

CluelessInSeattl(R)

Seattle, USA,
20.12.2012, 18:14

@ Rugxulo
 

DOS utility to display 1st line of all files in directory?

> I had thought QBASIC (QBASIC.EXE, QBASIC.HLP) was always installed.

Yup! You were right! I mistakenly thought QBASIC would be installed in its own directory, and finding no such directory I assumed I didn't have it on my machine. But after reading your remark, I searched my C:\ drive for QBASIC.*, and sure enough, those two files showed up in the DOS folder. Duh! My handle ain't "Clueless" without reason.

So I copied the text of your batch file into a file called ONELINE.BAT and then copied that file over to my little laptop running MS-DOS.

But when I ran it, it only got as far as running QBASIC, which then flashed briefly onto the screen for a only microsecond, and then the DOS prompt gave me the "File not found" error.

Would you have the time (and the patience) to help me try to troubleshoot this?

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Rugxulo(R)

Homepage

Usono,
20.12.2012, 21:10

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> So I copied the text of your batch file into a file called ONELINE.BAT and
> then copied that file over to my little laptop running MS-DOS.
>
> But when I ran it, it only got as far as running QBASIC, which then flashed
> briefly onto the screen for a only microsecond, and then the DOS prompt
> gave me the "File not found" error.

QBASIC included with MS-DOS is only an interpreter. And it doesn't support features of the full QB4.5 compiler suite. One of those missing features is argc, argv support. So I had to use a workaround which relies on %MYFILE% being set before running it. ONELINE.BAT was supposed to handle that for you by using its own argument as the %MYFILE% value. I can only guess that you didn't tell it what filename. Try using OUTER.BAT (below) instead, and see if that works better.


@echo off
REM outer.bat
for %%a in (*.txt) do call oneline.bat %%a

CluelessInSeattl(R)

Seattle, USA,
28.12.2012, 17:42

@ Rugxulo
 

DOS utility to display 1st line of all files in directory?

I wrote:
> > But when I ran it, it only got as far as running QBASIC, which then
> flashed
> > briefly onto the screen for a only microsecond, and then the DOS prompt
> > gave me the "File not found" error.

You replied:

> QBASIC included with MS-DOS is only an interpreter. And it doesn't support
> features of the full QB4.5 compiler suite. One of those missing features is
> argc, argv support. So I had to use a workaround which relies on %MYFILE%
> being set before running it. ONELINE.BAT was supposed to handle that for
> you by using its own argument as the %MYFILE% value.

I'm afraid all of that went over my head. It's been well over a decade since I wrote any BASIC code or batch files, and in the meantime I've suffered severe memory loss and cognitive impairment. *sigh*

> I can only guess that
> you didn't tell it what filename.

Hmmm? At the DOS command line? Like this: ONELINE *.txt ?

> Try using OUTER.BAT (below) instead, and
> see if that works better.

Am I supposed to insert that into the ONELINE.BAT code, substitute it for something in the orignal file or run it as a standalone batch file?
>
>
> @echo off
> REM outer.bat
> for %%a in (*.txt) do call oneline.bat %%a
>

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

CluelessInSeattl(R)

Seattle, USA,
26.12.2012, 16:32

@ Rugxulo
 

DOS utility to display 1st line of all files in directory?

Hi again, Rugxulo!

I'm afraid I've been out of the loop for a while due to illness and the demands of the holiday season. But I'm making an effort to get back to work on this project again (though it's still difficult for me to spend much time at the computer).

In that BAT file you posted for me, I see that it calls a QBASIC program called ONELINE.BAS. Where can I find a copy of that?

Will in Seattle
a.k.a. "Clueless"

> Anyways, here's a quick .BAT / .BAS combo I whipped up that should work
> verbatim in MS-DOS 6. (I assume this does what you want, otherwise you
> might have to use
> Sed,
> Awk,
> Edlin, or similar utility from wherever):
>
>
> @echo off
> REM Usage:  for %a in (*.txt) do call oneline.bat %a
> set B1=%TEMP%.\oneline.bas
> echo OPEN ENVIRON$("MYFILE") FOR INPUT AS #1 >%B1%
> echo INPUT #1, line$ : PRINT line$ >>%B1%
> echo CLOSE >>%B1%
> echo SYSTEM >>%B1%
> :begin
> set MYFILE=%1
> qbasic /run oneline.bas
> for %%z in (MYFILE B1) do set %%z=
>

Rugxulo(R)

Homepage

Usono,
26.12.2012, 23:05

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> Hi again, Rugxulo!
>
> In that BAT file you posted for me, I see that it calls a QBASIC program
> called ONELINE.BAS. Where can I find a copy of that?

It's inline in the .BAT itself, see below. It's basically a temporary "scrap" code file that is written to %TEMP% then executed.


OPEN ENVIRON$("MYFILE") FOR INPUT AS #1
INPUT #1, line$ : PRINT line$
CLOSE
SYSTEM


> >
> > @echo off
> > REM Usage:  for %a in (*.txt) do call oneline.bat %a
> > set B1=%TEMP%.\oneline.bas
> > echo OPEN ENVIRON$("MYFILE") FOR INPUT AS #1 >%B1%
> > echo INPUT #1, line$ : PRINT line$ >>%B1%
> > echo CLOSE >>%B1%
> > echo SYSTEM >>%B1%
> > :begin
> > set MYFILE=%1
> > qbasic /run oneline.bas
> > for %%z in (MYFILE B1) do set %%z=
> >

CluelessInSeattl(R)

Seattle, USA,
31.12.2012, 17:24

@ Rugxulo
 

DOS utility to display 1st line of all files in directory?

I finally figured out why my old SEEFIRST.EXE program (compiled from my SEEFIRST.BAS QuickBASIC file) kept crashing.

My old code contained a SHELL DIR>FILE.LST command.

And somewhere along the line I changed the switches on my DIR command, so that the file produced by DIR was not what my program expected it look like. So it choked.

Once I figured out the source of the problem, it was easy to correct.

But, I'd still like to get Rugxulo's BAT file up and running, as it seems to be a much more elegant way to accomplish the same task.

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Rugxulo(R)

Homepage

Usono,
03.01.2013, 10:55

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> But, I'd still like to get Rugxulo's BAT file up and running, as it seems
> to be a much more elegant way to accomplish the same task.

Sorry, been busy and distracted, never had enough energy or time to fully reply. (Not sure I do now either, sorry.)

The long answer is that it always depends on what you're trying to do and how you want to do it. "There is more than one way to skin a cat", as they say. I'm not sure what to tell you, esp. since even the QBASIC way is less universal and portable and kinda kludgy.

For simple text manipulation, you're better off using an appropriate scripting language or standard tool, e.g. awk, sed, rexx, head, tail, etc. While QBASIC has its virtues, esp. being pre-installed in (most common) MS-DOS setups, it's not necessarily the easiest, cleanest, most portable, or most robust (and easy to use) tool, at least in this case.

Part of the appeal of suggesting QBASIC (though lacking easy access to cmdline args) was so you wouldn't have to download anything extra. But it would be easier (in the long run) to just read up on Sed and AWK or similar. That way your work will work on any platform that supports those (DOS, OS/2, Win, *nix, Mac). And the fact that they are pretty small doesn't hurt either (even if it is a minor extra hassle to download them).

j_hoff(R)

19.12.2012, 09:47

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> I'd love to give it a try. But I have one big concern, and that is whether
> or not installing it would interfere with the execution of commands in my
> existing version of MS-DOS 6.21.
>
> I depend on a large number of batch files, some of them rather complicated,
> for executing series of my most frequently used commands. I use a text
> editor with a built in macro language that allows me to call DOS commands
> and batch files from keyboard shortcuts from within the editor.

One (of many others) way to get the job done, which does not require you to change to another DOS version or an alternative shell, could be like this:

1. write a short batch file and name it 'HEAD.BAT':
@ECHO OFF
FAM /L-2 < %1

2. execute the following (example) command:
FOR %f IN (*.txt) DO CALL HEAD %f

You can find the program FAM as part of the package DOSUTILS.ZIP which, in-turn you will find here: http://www.bttr-software.de/products/jhoffmann/

Of course using the program FAM for the purpose of just displaying the first line of a file is kind of overkill, as this program can do much more, but if you make intensive use of batch programming you might be interested in the various utilities of the DOSUTILS package anyway. So just give it a try.

ron(R)

Homepage E-mail

Australia,
18.12.2012, 22:48

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> I thought I once had a little DOS utility that would display a list of the
> first lines of all the text files in a specified directory.
>
> Do any of you know of such a utility that would work in MS-DOS 6.21?

Is this any use to you ?

http://www.ausreg.com/files/freebe.exe

Place it in your path, then go to the directory and type "freebe".
You will get a display of all .txt files matched with the first line (unless first line is empty).
Highlighting a file name and pressing EnteR will display the file contents.

Was written in MS-DOS 6.20.

CluelessInSeattl(R)

Seattle, USA,
19.12.2012, 18:10

@ ron
 

DOS utility to display 1st line of all files in directory?

> Is this any use to you ?
>
> http://www.ausreg.com/files/freebe.exe

Thanks, ron!

I gave freebe.exe a try.

It seems to be configured to only display files with .txt extensions.

Do you know if it can be configured to display the first line of all the files in a directory?

Will in Seattle
a.k.a. "Clueless"

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

ron(R)

Homepage E-mail

Australia,
19.12.2012, 22:28
(edited by ron, 19.12.2012, 22:39)

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> > http://www.ausreg.com/files/freebe.exe
> Thanks, ron!
> I gave freebe.exe a try.
> It seems to be configured to only display files with .txt extensions.

Yes, that is so.

> Do you know if it can be configured to display the first line of all the
> files in a directory?

I can re-jig it to include other extensions, but they have to be ASCII files.
It will not read binaries.

What did you have in mind ?

OTOH: I have something similar that will ALSO list the <title> of .htm files and display small renderings of images, and just list other files, but the output is an .htm file.
I use that with Arachne, but it will run from the CLI.

see: http://www.ausreg.com/files/dir2htm.zip
read: http://www.ausreg.com/files/dir2htm.txt

Doug(R)

E-mail

21.12.2012, 00:26

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

Will -

Here is a location of the UNIX > DOS utility Head:

  http://reimagery.com/fsfd/unix.htm#uxutl

A little further down the page, after the utility descriptions, you will find download links. Download the file:

  uxutl23b.zip

Unzip it to get the HEAD.EXE file.

Usage:  HEAD [-n] [filespec...]

where:  n  is the number of lines from the file to display.
        filespec  is the specification of files to display.

Must give -n before filespec on command line.

Wildcards (* and/or ?) accepted in/as filespec.

Output can be redirected to file, for example:

  head -1 a:*.* > c:\archive\file.txt

Does not accept slash / as switch character (must use dash -).

Does not pause scrolling after a screenful of display -- must use MORE or somesuch filter to pause, for example:

  head -1 a:*.* | more

- Doug B.

CluelessInSeattl(R)

Seattle, USA,
21.12.2012, 16:40

@ Doug
 

DOS utility to display 1st line of all files in directory?

> Here is a location of the UNIX > DOS utility Head:
>
> http://reimagery.com/fsfd/unix.htm#uxutl
>

> Must give -n before filespec on command line.
> - Doug B.

Thanks a million, Doug!

This looks like the key that will get me into the ballpark.

Do you know if there's a "negative" filespec command? By which I mean a way to tell Head to ignore certain obviously non-text filetypes such as *.EXE, *.COM, and the like?

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

CluelessInSeattl(R)

Seattle, USA,
21.12.2012, 17:00

@ CluelessInSeattl
 

DOS utility to display 1st line of all files in directory?

> I thought I once had a little DOS utility that would display a list of the
> first lines of all the text files in a specified directory.
>
> I thought it was called DIRFIRST.
>
> But I can't find it on any of my old floppies.
>
> And when I Google "DIRFIRST" I get something completely different.
>
> Could I be thinking of an old CP/M utility?

If any of you are interested, I finally tracked down that old utility, and it was indeed called DIRFIRST.COM.

Last night I dug through boxes of old 5.25 disks from my days running CP/M on a bunch of Kaypros, and found a neatly labeled utility disk on which I'd pasted a printout of the disk's directory, and, lo and behold, there it was: DIRFIRST.COM.

So, that explains why I've struck out over and over again trying to find it on websites with old DOS utilities. It's not a DOS utility at all. It was a CP/M utility.

So, this morning when I Googled: cp/m OR cpm dirfirst.com utilit*

I got a number of hits, including this one, a list of CP/M utilities compiled back in 1986 by fellow Seattleite Norm Gregory.

I also found a scrap of an old yellowed printout on pinfeed paper of the Qbasic or QuickBasic code I wrote back in the mid 90s to try to produce a DOS program that would do what DIRFIRST.COM did. I called it SEEFIRST, and then later, CFIRST. But I'll be danged if I can find the disk with the .BAS file for that program.

I do have a compiled .EXE version of it, but it stalls when I try to run it. I think I've forgotten what parameters to enter on the command line. I know it used to work for me way back when. I kept it in the UTILITY folder on my DOS machine, along with BRUN45.

Anyway, it looks like you guys are providing me the tools I'm going to need to come up with an elegant batch file that will duplicate what that old CPM utility used to do so well.

Many thanks!

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Back to index page
Thread view  Board view
15196 Postings in 1365 Threads, 250 registered users, 19 users online (0 registered, 19 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum