Live data from Hacker News

look(1): lines beginning with given string

linux.die.net

1–10 of 47 posts

Re: look(1): lines beginning with given string

#6
post #5

Is look of any use? Isn't grep fast enough?

A better one-line description would be "look(1): binary search for lines with a given prefix in a sorted file" Which tells you exactly what the pros/cons are compared to plain grep.

I created a 1.1G file with dictionary words and timed...

  % du -h a  
  1.1G	a
  % time look 'dog' a | wc -l
  53856

  real	0m0.021s
  user	0m0.020s
  sys	0m0.003s
  % time grep '^dog' a | wc -l
  53856

  real	0m28.593s
  user	0m0.977s
  sys	0m2.223s
Ok grep performed worse than what I expected (sort took a long time though).

Re: look(1): lines beginning with given string

#7
post #5

Earlier quoted context omitted.

A better one-line description would be "look(1): binary search for lines with a given prefix in a sorted file" Which tells you exactly what the pros/cons are compared to plain grep.

I created a 1.1G file with dictionary words and timed... % du -h a 1.1G a % time look 'dog' a | wc -l 53856 real 0m0.021s user 0m0.020s sys 0m0.003s % time grep '^dog' a | wc -l 53856 real 0m28.593s user 0m0.977s sys 0m2.223s Ok grep performed worse than what I expected (sort took a long time though).

Is grep optimized to be fast, though? There seems to be a lot of, "better at grep than grep" tools out there,

http://beyondgrep.com/

Re: look(1): lines beginning with given string

#8
When running 'look' to get all comments in a file I only get the first found line in the ouput. Can someone explain this?

look "#" .zshrc

There are really a lot more comments (lines starting with '#') in my .zshrc then the first line.

Re: look(1): lines beginning with given string

#9
post #3
post #2

The universe of Unix filters never ceases to turn up things I haven't seen before. Other examples for those inclined: tac, sponge, pv, join, paste.

Some others I like: rev, vipe, comm, bfr, xxd

Do you know of a good resource listing all of these?

Re: look(1): lines beginning with given string

#10
post #5

Earlier quoted context omitted.

A better one-line description would be "look(1): binary search for lines with a given prefix in a sorted file" Which tells you exactly what the pros/cons are compared to plain grep.

I created a 1.1G file with dictionary words and timed... % du -h a 1.1G a % time look 'dog' a | wc -l 53856 real 0m0.021s user 0m0.020s sys 0m0.003s % time grep '^dog' a | wc -l 53856 real 0m28.593s user 0m0.977s sys 0m2.223s Ok grep performed worse than what I expected (sort took a long time though).

'look' can stop working when it finishes the sorted section of 'dog', whereas grep must continue to the end of the file.

Ignoring memory hierarchy, naturally 'look' would be O(log n) while grep would be O(n).

Special input (sorted in this case) of course often calls for matching algorithms, when speed matters.

Post reply on HN