News for hackers. Stuff that matters.

polegone

Re:Gonix – Unix tools written in Go on Saturday May 09, 2015 @06:30PM (#9517942)
No problem.
Re:Gonix – Unix tools written in Go on Saturday May 09, 2015 @12:37PM (#9516839)
I linked it in the readme so all those people visiting my project will see yours.

I can't help much myself (you are way ahead of me), but more people should visit your project now.

Re:Gonix – Unix tools written in Go on Saturday May 09, 2015 @03:06AM (#9515760)
I tested it by on a several megabyte text file (not that large) and I can see a huge improvement in speed when I use a reader vs. loading the whole thing into memory as I did at first.

I can see now how much of a difference it can make on a really large file, like in the gigabyte range.

BTW, I deleted my earlier comment because the problem I had wasn't anything to do with bufio. I had just made an obvious mistake elsewhere in my code, which I've fixed now.

Re:Gonix – Unix tools written in Go on Saturday May 09, 2015 @12:49AM (#9515536)
I am a novice, and that is one of the reasons why I started this project (to learn).
Re:Gonix – Unix tools written in Go on Saturday May 09, 2015 @12:37AM (#9515511)
I must say that yours is much more complete than mine, though.
Re:Gonix – Unix tools written in Go on Friday May 08, 2015 @11:16PM (#9515347)
I'm working on that as well. I just fixed cat to crash and log on error, and I'll be fixing the other commands soon.

By the way, I'm wondering how I should go through the file line by line with a reader.

I think the most efficient way may be to scan byte by byte from the start (head) or the end (tail), and count until reaching n amount of newlines (or stop if at the end of the file), then print the bytes between the start/end and the nth newline.

How does this sound?

Re:Gonix – Unix tools written in Go on Friday May 08, 2015 @10:16PM (#9515183)
Thank you. I will look into this.
Re:Gonix – Unix tools written in Go on Friday May 08, 2015 @10:15PM (#9515180)
I'm just doing this for fun and to learn about Go and Unix at the same time.

I am a beginner, and a lot of my code is inefficient and/or incomplete, but by putting it on the Internet I can get criticism and find out where I went wrong.

For instance, some of you have told me that the way I've been reading files is very inefficient, so now I'll try and do it the correct way.