• Welcome to Valhalla Legends Archive.
 

[Ruby] tokenls - find tokens in files

Started by Joe[x86], April 25, 2011, 09:02 PM

Previous topic - Next topic

Joe[x86]

First, this board needs a ruby forum. I write lots of things that I find kinda neat that I hope other people could use.

Code: https://gist.github.com/940265

Basically, I want to be able to search a file or files without having to open them, such as in a compile script or whatnot. Generally, it's for the words "to do" or something like that, to remind myself that I still need to do something.

Consider this test file:
[william@NCC-1701 ~/Dropbox]$ cat /tmp/filewithtokens
this is a test file
some of these lines have no tokens
but other lines do have to do tokens
like that one, but not this one


If I want to test it for the default tokens, I can do this:
[william@NCC-1701 ~]$ tokenls /tmp/filewithtokens
/tmp/filewithtokens:3: but other lines do have to do tokens


Perhaps you want to keep a really simple calendar:
[william@NCC-1701 ~]$ cat /tmp/appointments
2011/04/23 5:30PM Do something
2011/04/26 5:30PM Do something else


What do you have to do on the 26th?
[william@NCC-1701 ~]$ tokenls --tokens=2011/04/26 /tmp/appointments
/tmp/appointments:2: 2011/04/26 5:30PM Do something else


All the token checking is case insensitive, which I think is better since this was intended for code. If anyone has any ideas on how this could be made better, let me know. :)
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Joe[x86]

That doesn't show you the filename (if you're doing multiple files) or the line the token appears on. I can tell I'm getting tired though because I felt like I wasted a ton of time for a few seconds there.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

rabbit

Sorry.

cat * | grep -Hin "Do something"
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.