Valhalla Legends Forums Archive | General Programming | [Ruby] tokenls - find tokens in files

AuthorMessageTime
JoeTheOdd
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:
[code][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[/code]

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

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

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

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. :)
April 26, 2011, 2:02 AM
rabbit
cat * | grep "Do something"

???
April 26, 2011, 2:50 PM
JoeTheOdd
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.
April 27, 2011, 8:53 AM
rabbit
Sorry.

cat * | grep -Hin "Do something"
April 27, 2011, 1:35 PM
JoeTheOdd
[quote author=rabbit link=topic=18275.msg185165#msg185165 date=1303911335]
Sorry.

cat * | grep -Hin "Do something"
[/quote]

:(
April 27, 2011, 4:10 PM

Search