Thread View: demon.ip.developers
8 messages
8 total messages
Started by John Washington
Wed, 11 Nov 1998 00:00
grep 'n edit, I wish!
Author: John Washington
Date: Wed, 11 Nov 1998 00:00
Date: Wed, 11 Nov 1998 00:00
40 lines
1970 bytes
1970 bytes
OK, this is going to be pretty contrived if I'm to get
the IP part of the charter into this posting, but traffic
is getting a bit quiet in this group, so maybe you'll
welcome ANYthing. :-)
I constantly find myself typing things like:
grep foobar *.c
[pause to eyeball result]
edit thisfile.c thatfile.c tother.c yafile.c etc.c
And that really bugs me. The damn computer knows which files
I want already. I could even have used the -l option in grep
to get a little list of them.
For several years the synapses down the far end of my tail have
been reckoning it should be a SMoP to somehow generate that
command line for me. I could just type
e foobar
and somehow, after a short whirr and churn, I'd be inside the
editor with all those relevant files ready to roll.
I can't stand it any longer. The message has at last got up to
my brain that if I don't know how to do it, one of you can, Shirley?
Oh, and yes OF COURSE it's easy-peasy in Unix, but being a
dinosaur I'm running msdos.
Can anyone help? Please?? It would make my life so much more
pleasant when browsing code such as Snews and Ka9q. Phew! At
last something to get on-topic with IP. :-)
P.S. What do others feel? Is this kind of digression unwelcome,
or should we sometimes use this as a forum to exchange useful
development tools, tips and tricks? Or are there better places
in Usenet for this?
John Washington
Re: grep 'n edit, I wish!
Author: pete$no$pam
Date: Wed, 11 Nov 1998 00:00
Date: Wed, 11 Nov 1998 00:00
88 lines
3263 bytes
3263 bytes
In article <910784101snz@wash.demon.co.uk>
john$@wash.demon.co.uk "John Washington" writes:
> OK, this is going to be pretty contrived if I'm to get
> the IP part of the charter into this posting, but traffic
> is getting a bit quiet in this group, so maybe you'll
> welcome ANYthing. :-)
_Almost_ anything :-)
>
> I constantly find myself typing things like:
>
> grep foobar *.c
> [pause to eyeball result]
> edit thisfile.c thatfile.c tother.c yafile.c etc.c
>
> And that really bugs me. The damn computer knows which files
> I want already. I could even have used the -l option in grep
> to get a little list of them.
>
> For several years the synapses down the far end of my tail have
> been reckoning it should be a SMoP to somehow generate that
> command line for me. I could just type
>
> e foobar
>
> and somehow, after a short whirr and churn, I'd be inside the
> editor with all those relevant files ready to roll.
>
> I can't stand it any longer. The message has at last got up to
> my brain that if I don't know how to do it, one of you can, Shirley?
BATCH is your friend. Try the following GREPEDIT.BAT - call
it what you like:
@echo off
if %1.=={%0}. goto addfile
if %2.==. goto error
Rem
Rem Usage is: %0 greptext filelist
Rem eg. %0 buffer *.c
Rem
Rem Ensure you have enough environment space...
Rem
set args=
echo Grepping...
for %%f in (%2) do call %0 {%0} %1 %%f
if %args%.==. goto nofiles
Rem fix the line below for your editor - mine is Qedit
q %args%
echo.
set args=
goto end
:nofiles
echo No files found containing %1
goto end
:error
echo Bad args: usage is %0 greptext filelist
goto end
:addfile
sgrep -l %2 %3
if errorlevel 1 goto end
set args=%args% %3
:end
..
> Can anyone help? Please?? It would make my life so much more
> pleasant when browsing code such as Snews and Ka9q. Phew! At
> last something to get on-topic with IP. :-)
Just try: grepedit my_stuff *.c in your snews dir...
> P.S. What do others feel? Is this kind of digression unwelcome,
> or should we sometimes use this as a forum to exchange useful
> development tools, tips and tricks? Or are there better places
> in Usenet for this?
What is development without tools? In a general sort of way
I see no problem with discussing hints and tips like the
above, keeping in mind the IP bit of the group. So long as
things do not degrade into wars about editors and compilers
etc.
--
Pete
Re: grep 'n edit, I wish!
Author: Walter Briscoe
Date: Wed, 11 Nov 1998 00:00
Date: Wed, 11 Nov 1998 00:00
31 lines
1786 bytes
1786 bytes
In article <910784101snz@wash.demon.co.uk>, John Washington <john$@wash.demon.co.uk> writes [snip] >I constantly find myself typing things like: > > grep foobar *.c > [pause to eyeball result] > edit thisfile.c thatfile.c tother.c yafile.c etc.c > >And that really bugs me. The damn computer knows which files >I want already. I could even have used the -l option in grep >to get a little list of them. It knew the files which measured up before you threw the information away. tee may be useful. Unfortunately, doze does not have a true pipe capability. e.g. command1 | command2 is roughly equivalent to command1 > tmpfile command2 < tmpfile del tmpfile Consequence is that none of the results of command2 comes out before command 1 finishes. [snip] In Unix, I solve such problems with a script which takes arguments of a searchstring and a filespec. find generates filelist; grep -l filters it; $VISUAL (elvis, vim or vi) edits each file in turn. It took me ages to appreciate I REALLY needed such a tool. It might be possible to right your own piping code to exchange the problems with gates code for your own. -- Walter Briscoe
Re: grep 'n edit, I wish!
Author: Graham E Kinns
Date: Wed, 11 Nov 1998 00:00
Date: Wed, 11 Nov 1998 00:00
43 lines
2028 bytes
2028 bytes
In article <910784101snz@wash.demon.co.uk>
john$@wash.demon.co.uk "John Washington" writes:
>I constantly find myself typing things like:
>
> grep foobar *.c
> [pause to eyeball result]
> edit thisfile.c thatfile.c tother.c yafile.c etc.c
>
>And that really bugs me. The damn computer knows which files
>I want already. I could even have used the -l option in grep
>to get a little list of them.
>Oh, and yes OF COURSE it's easy-peasy in Unix, but being a
>dinosaur I'm running msdos.
If you have a DJGPP compiled editor & grep:
grep -l foobar *.c | xargs emacs (xargs is from findutils)
or if you're into bash:
bash -c 'emacs `grep -l foobar *.c`'
or just:
grep -l foobar *.c > cmdfile
emacs @cmdfile
Depending on the editor, you could call grep -l from within the
editor and parse the results. Alternatively something like
'emacs *.c' and search the files from within the editor. I believe
there's a DJGPP port of VIM available...
Current DJGPP FAQ for reference:
ftp://ftp.demon.co.uk/pub/mirrors/simtelnet/gnu/djgpp/v2/faq211b.zip
Cheers, Graham.
--
Graham E. Kinns -------------------------- <Graham@grempc.demon.co.uk>
"I've done many things that have gotten very popular but amongst a
sorta nerdy community ... because the kinda stuff I do is stuff that
I have no idea how to explain it to my mom" - James Gosling.
Re: grep 'n edit, I wish!
Author: Chris Croughton
Date: Wed, 11 Nov 1998 00:00
Date: Wed, 11 Nov 1998 00:00
81 lines
3628 bytes
3628 bytes
In article <910784101snz@wash.demon.co.uk>
john$@wash.demon.co.uk "John Washington" wrote:
> grep foobar *.c
> [pause to eyeball result]
> edit thisfile.c thatfile.c tother.c yafile.c etc.c
>
>And that really bugs me. The damn computer knows which files
>I want already. I could even have used the -l option in grep
>to get a little list of them.
You mean:
edit `grep -l foobar *.g`
?
>For several years the synapses down the far end of my tail have
>been reckoning it should be a SMoP to somehow generate that
>command line for me. I could just type
>
> e foobar
Well, you could alias it...
>I can't stand it any longer. The message has at last got up to
>my brain that if I don't know how to do it, one of you can, Shirley?
>
>Oh, and yes OF COURSE it's easy-peasy in Unix, but being a
>dinosaur I'm running msdos.
Not a problem, there's a port of GNU C called DJGPP which emulates Unix
type command lines. It would be easy to write a program which took the
appropriate command line (including the backquotes to run grep or
whatever) and called your editor with the result as the arguments. The
only thing you have to be careful about is that most MSDOS programs can't
handle and argument list longer than 127 characters - you could of course
make it call the editor once for each file instead.
It may also be possible to do something similar using a 4DOS batch file
(if you are still using COMMAND.COM, seriously you should use 4DOS
instead). In fact I'm pretty sure it can be done fairly easily,
especially in recent (v6) versions.
In fact:
@echo off
setlocal
grep -l "%1" %2 > \tmp\1
set x=
do i = 0 to %@lines[\tmp\1]
set x=%x %@line[\tmp\1,%i]
enddo
edit %x
Works for me (it does assume that you don't mind overwriting file \tmp\1,
and it calls 'edit' with the list of files which probably won't work for
you, but those can be easily hacked). You call it as
editgrep foobar *.[ch]
>Can anyone help? Please?? It would make my life so much more
>pleasant when browsing code such as Snews and Ka9q. Phew! At
>last something to get on-topic with IP. :-)
<g> Thanks for the idea - now I'll rewrite it a lot more efficiently (and
a lot less understandable) as a bash script (did I mention that there's a
DJGPP port of bash - the GNU version of the Bourne shell - for DOS as
well?). And then the zsh version which will be all on one line <g>...
>P.S. What do others feel? Is this kind of digression unwelcome,
>or should we sometimes use this as a forum to exchange useful
>development tools, tips and tricks? Or are there better places
>in Usenet for this?
There probably are, but I certainly don't see them (far too high traffic,
for instance on the DJGPP newgroup). As far as I'm concerned, the
occasional request of this nature isn't exactly overloading the newsgroup,
in fact it's nice to have some reassurance that it's still there...
Chris C
Re: grep 'n edit, I wish!
Author: John Washington
Date: Sun, 15 Nov 1998 00:00
Date: Sun, 15 Nov 1998 00:00
63 lines
3768 bytes
3768 bytes
Many thanks to everyone who followed up or emailed me on this topic, especially Pete. I think his solution is ideal for my needs, as soon as I lay my hands on sgrep (Borland's grep doesn't appear to give exit codes that indicate whether any matches were found, so I shall need sgrep). Yes, sure enough, I'm told it's easy with Unix, and indeed I am currently reconfiguring a 486/25 that I hope eventually will run either Linux or FreeBSD. Though why I would use Unix to do development for DOS escapes me. Not that I'm against cross-platform development -- I've done a fair amount of Unix development using DOS! (Using ftp over a lan to xfer the source files). That comes down to personal taste about editors. Yes, I've used vi. I've even read a book about its many powerful features. And it can do a lot more than any free- or share- ware DOS editor I've seen, even though Qedit is pretty good. I'll only listen to vi fanatics if they've also given Brief an extensive trial. The big problem I see with vi and its brethren is that they come from an era when editors were designed around serial connected terminals, not memory mapped displays. IMO that's rather limiting, no matter how good the designer is (and vi's designer did a great job, considering the constraints). I paid several hundred dollars for Brief, great great value. If only I could have the source code to port it to other systems! I especially appreciated Pete's solution because it doesn't rely on the immensely powerful 4DOS. 4DOS is really great, but I've refused to allow it on my PC because I've seen too many programmers come to grief. Out goes a product, and tucked away somewhere is a .bat file. Soon afterwards the tech support lines melt down as users who _don't_ use 4dos ring and ring and ring. However, it may be time for me to abandon that prejudice -- it's well over a year since I last did any paid work on DOS software and I don't expect any more. I couldn't follow the comments about DJGPP. As I understand it, this assumes I have the source code for the editor. This seems to me to be putting the cart before the horse. Much as I'd love to be able to recompile Brief, I don't choose my editors on the basis of whether or not source code is available unless other factors are equal. Where do I find an editor with source code, that runs fast in DOS, has no significant limits on file size, can use regular expressions, has its own C-like very powerful language (also a LISP-like language, but that's no benefit for me), completely flexible key bindings, can be configured with a knowledge of the syntax of various languages (C, Pascal, dBase, etc), comes with a manual about 3" thick (I've met people with pirate copies of Brief who didn't have a clue how powerful it is), has lots of extra macros available on the Internet written by happy users, etc, etc, etc... ? <yawn> OK, I don't want to get religious about this. :-) However, the comments about DJGPP do serve to heighten my desire for source of all the tools I use. So thank you to everyone. I'm very happy with the responses I had in this thread, much appreciated. -- John Washington --
Re: grep 'n edit, I wish!
Author: pete$no$pam
Date: Mon, 16 Nov 1998 00:00
Date: Mon, 16 Nov 1998 00:00
22 lines
1469 bytes
1469 bytes
In article <911169745snz@wash.demon.co.uk>
john$@wash.demon.co.uk "John Washington" writes:
> Many thanks to everyone who followed up or emailed me on this
> topic, especially Pete. I think his solution is ideal for
> my needs, as soon as I lay my hands on sgrep (Borland's
> grep doesn't appear to give exit codes that indicate
> whether any matches were found, so I shall need sgrep).
Point your http-grabber at (I think):
www.pdlmail.demon.co.uk/utils/sgrep09.zip
where you should find a working[1] .exe plus the C source.
Whether or not said source can be coerced into compiling
cleanly under BC 3.1 and running correctly is left as an
exercise for the reader :-)
Pete
[1] Depending on your definition of "working" :-) It works
for me though.
Re: grep 'n edit, I wish!
Author: Terrance Richard Boyes
Date: Mon, 16 Nov 1998 00:00
Date: Mon, 16 Nov 1998 00:00
22 lines
1844 bytes
1844 bytes
John Washington <URL:mailto:john$@wash.demon.co.uk> wrote: > ware DOS editor I've seen, even though Qedit is pretty good. I'll > only listen to vi fanatics if they've also given Brief an > extensive trial. The big problem I see with vi and its brethren Well I haven't even heard of Brief, I used to use PFE on the PC for Windows-based tasks, vim for DOS based ones. > is that they come from an era when editors were designed around > serial connected terminals, not memory mapped displays. IMO > that's rather limiting, no matter how good the designer is (and Ah, but you haven't allowed for Bram :) Vim has for a while been far superior to vi (not least 'cos the source is available and compiles without too much trouble on Amiga, PC and various UNIX' - plus others). But the recent versions may be of interest, GVIM from <URL:ftp://ftp.vim.org/pub/vim> adds menu's, Windows copy/paste etc... for some windowing systems. -- <URL:http://www.pierrot.co.uk/> Team AMIGA Women's Libbers are OK. I just wouldn't want my sister to marry one.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads