gnu grep on R-Pi
Pages: 1 2
neil.r (1738) 66 posts |
I’m sure I’m doing something incredibly stupid here, but I can’t work out what… I installed !grep from PackMan on an R-pi, but cannot for the life of me work out how to use wildcards for the filename. If I run ‘grep pattern *’ I get no output. If I run, say, ‘grep pattern *.htm’ I get a match in a single file, when I know that the pattern is in multiple files. Do I need to escape the ‘*’ character in the filename somehow? Sorry, I know I should be able to work this one out, but I’ve been trying now for over an hour to get a simple grep to work across a bunch of html files, and I just can’t get it to work the way the documentation suggests it should. Thanks, |
Raik (463) 2061 posts |
Im not sure. It is to long ago. You can download my grep frontend based on the frontend module. A !Help with a wildcard-section is inside. |
neil.r (1738) 66 posts |
Thanks for that, but I still can’t get grep to return the results I’d expect. Has anyone else got a Pi that they could test with? I still reckon I’m doing something stupid, but I’m just going round in circles now. How should it work? Like unix? Or am I missing some RISC OS specific convention? All I’ve done is install grep from !PackMan and attempted to use it as per the helptext, with “grep pattern *” or “grep pattern */htm” – the current directory is correctly set. |
neil.r (1738) 66 posts |
OK, here’s an odd thing. I execute the same command twice, and it returns different results. This is a straight cut&paste from a command line: *grep TZR *.htm *grep TZR *.htm He mentions that a TZR250 is a good way to start, and this seems good bike? TZR250, as it's (relatively) cheap, won't scare the crap out of BMCRC, as they're close by, and run a large TZR class. So, now I knew will be running the TZR class for a while yet, and it's a good class Ian Bassett who has a ready to race TZR up for grabs. So far Drive over to Thamesmead to meet Ian and his amazing performing TZR. I the rest of the TZRs there. Some of them look frighteningly serious, but at least there's one guy there who's got a TZR with a worse colour entered the three TZR races on the day, as a) I'm not sure how I genuinely don’t understand this now! |
Jeffrey Lee (213) 6048 posts |
I tend to just use ‘grep pattern .’ to search all files. Potentially ‘grep pattern @’ on RISC OS if grep is using RISC OS format filenames instead of unix (@ is RISC OS’s equivalent of unix’s .) I’m not sure what style filenames the version of grep in packman expects, but I’d expect at least one of the above to produce what you’re after. I’ve never really used wildcarded filenames with grep on RISC OS, so I’m not sure whether they usually work or not. |
neil.r (1738) 66 posts |
Nope, no joy: *grep TZR . /SDFS::RISCOSpi.$/Apps/Utilities/!grep/grep: . *grep TZR @ /SDFS::RISCOSpi.$/Apps/Utilities/!grep/grep: @ That string should be in multiple files. I’ve got a copy of the same directory on a linux machine: neil@raspberrypi /mnt/usbdisk/race diary $ grep -c TZR *.htm d_199707.htm:9 d_199708.htm:4 d_199709.htm:2 d_199710.htm:10 d_199711.htm:2 d_199801.htm:5 d_199803.htm:1 d_199804.htm:2 d_199805.htm:3 d_199806.htm:4 d_199807.htm:4 d_199808.htm:2 d_199809.htm:4 d_199810.htm:6 d_199811.htm:1 d_199901.htm:9 d_199903.htm:4 d_199904.htm:7 d_199905.htm:8 d_199906.htm:2 d_199907.htm:7 d_199908.htm:0 d_199909.htm:4 d_199910.htm:6 d_199911.htm:7 d_200001.htm:6 d_200003.htm:2 d_200004.htm:4 d_200005.htm:1 d_200006.htm:1 d_200007.htm:1 d_200008.htm:0 d_200009.htm:0 d_200010.htm:0 d_200011.htm:0 d_200101.htm:0 d_200103.htm:0 d_200104.htm:0 d_200105.htm:0 d_200106.htm:0 d_200203.htm:0 d_200204.htm:1 d_200205.htm:0 d_200207.htm:0 d_200211.htm:0 d_200212.htm:2 d_200301.htm:1 d_200302.htm:7 d_200303.htm:0 d_200304.htm:5 d_200306.htm:1 d_200308.htm:5 If I execute exactly the same command on RISC OS, it stops after the first file: *grep -c TZR *.htm 9 * |
Rick Murray (539) 13840 posts |
What is “TZR”? Have you tried “
…and doesn’t appear to output the filename either. |
James Peacock (318) 129 posts |
The UNIX shell (e.g. bash) is expanding the wildcard before running grep. The normal RISC OS shell doesn’t do that and will pass ‘*.htm’ directly to grep. So, unless the copy of grep you are using was extended to simulate this wildcard expansion it isn’t going do what you want. What I suspect is happening is that ‘*.htm’ is getting interpreted a the name of a single file. IIRC this would cause the ‘first’ matching file to be opened. |
Raik (463) 2061 posts |
I have not a RISC OS Computer here so I’m not sure but I mean there is a filename wildcard enviroment to set. I remember a little bit it is desribe in my helpfile. It is long time ago as I need this. |
Fred Graute (114) 645 posts |
Try adding the ‘-r’ switch (as @ is a directory). With that added it works fine here. |
neil.r (1738) 66 posts |
Yes, I tried ‘grep pattern */htm’ and received an error that /htm wasn’t found. Which kind of makes sense (to me, at least), as I’m assuming that as a Unix utility it’s going to use Unix filenaming conventions? So, if ‘*.htm’ matches only one file, what should I use to search all files in a directory? ‘grep pattern *’ returns no matches. It doesn’t matter if I put the pattern to search for in quotes or not. And I don’t want to search recursively, as I’m already in the directory that I want to perform the grep. And the reason for searching only html files is that there are also many jpegs and other, non-text files in that directory that do not need searching. Is there a ‘native’ RISC OS grep I can use? I mean, somebody must have wanted to locate all incidences of a string in a set of files before now? I’m sure I must just be missing something staggeringly obvious. |
Martin Bazley (331) 379 posts | |
neil.r (1738) 66 posts |
Ah-ha! Looks promising. I’ll take a look. Thanks! |
Rick Murray (539) 13840 posts |
Which is why ports that bring in filename conventions from other filing systems are horrible and should be expunged from reality…with prejudice. [hint: there’s rather more to porting than just (re)compiling it on a different system] You might feel that is a strong opinion, but really, we can’t have this utility doing something with filenames, and that utility doing something totally different. [And if you don’t believe me, imagine the stink that would be created if you made a nifty utility for Linux, but insisted upon RISC OS style paths!]
That’s bizarre as it is pretty universal that a star is a multicharacter wildcard. I guess I ought to find grep and drop it in the emulator for a play.
Yes – I wrote a little program to do it over two decades ago. I’m off to download Textseek. ;-) |
neil.r (1738) 66 posts |
hint: there’s rather more to porting than just (re)compiling it on a different system Yup, I completely agree on this point. You can see the confusion that it causes to a beginner! Thanks to everyone for their help here. (Now to work out how to do quotes here…) |
GavinWraith (26) 1563 posts |
Has anybody tried Hvor (Danish for where) which you can download from http://www.wra1th.plus.com/zip/hvor.zip ? I wrote it as an exercise back in 2007. It uses Lua pattern syntax rather than Perl. I also wrote Gap which searches for two words separated by less than a given number of words. See http://www.wra1th.plus.com/throw.html . |
patric aristide (434) 418 posts |
I’m getting the following on my BB-xM (5.19 16.05.2012) Internal error: abort on data transfer at &000217C8
|
Steve Pampling (1551) 8170 posts |
Ah you will be wanting to type “b” and a “q” and a dot (as “bq.”) with a space after and then the quoted text. Then a space line after the quoted text. BTW. feel free to say how naff textile is, there won’t be any arguments. |
Jess Hampshire (158) 865 posts |
The forum used to block quote with a simple email style chevron, but that function went a while ago, unfortunately. |
neil.r (1738) 66 posts |
Well… as a newcomer I thought it best to keep my head below the parapet for a while first :) But I’ll admit to a certain amount of frustration trying to use the forum and wiki here from NetSurf. I just assumed it was some kind of initiation test… |
GavinWraith (26) 1563 posts |
Sorry. If I had tested it first in the RPi I would have remembered it needs recompiling. 2007 is a long time ago. I have now scrapped Hvor. Try !L—cate instead, from http://www.wra1th.plus.com/zip/l—cate.zip . I have tested it on the Raspberry Pi. The interface is unsophisticated, but it lets you search for a pattern in files or directories, recursively or not, allowing files with given filetypes whose leafnames match a given pattern. |
neil.r (1738) 66 posts |
Just a quick note to say that I grabbed !Textseek, and it works beautifully. Thank you! I’ll also give !L-cate a whizz this afternoon when I’ve got a few minutes. Again, thanks all for the help. |
neil.r (1738) 66 posts |
Having used Textseek for a bit, can I ask what the protocol would be for getting it included as a package that can be installed from PackMan? (assuming that the original author would permit this). I just think that it’s a very useful thing to have, which would have saved me a bit of grief had I found it initially. I think that other newcomers to RISC OS could also benefit from having it easily available. I’m happy to help out here if I can – I just don’t want to tread on anyones toes while I’m doing it. Ta. |
Alan Buckley (167) 232 posts |
It already is. I found this to be a very useful program and the author allowed me to package it a while ago. I’ve just double checked and it it in the package lists shipped with the RPi. |
neil.r (1738) 66 posts |
So it is! I looked through the list, got as far as THHeap and THSound, and assumed that it wasn’t. Of course, I hadn’t banked on H coming before e in the !PackMan sort order. Mea culpa. |
Pages: 1 2