Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this:

$ look "string" "/home/patrick/filename.txt"

However, this gives me the following message:

"look: /home/patrick/filename.txt: File too large"

So, I have two questions.

  1. How can I make this work with the "look" command and not any other commands such as "grep"?
  2. If I were to use "grep", would it take longer than using "look", provided that I can somehow get "look" to work on this large file.

Thanks!

What system are you on?

Sometimes you can get around this by having the shell open the file for it. Redirect it in instead of giving it the filename.

look string < giganticfile

This trick doesn't work for things which need to know how big the file is, but look doesn't strike me as one of them.

Thanks for the response. I'm using Ubuntu 10.10.
Trying out your suggestion from a shell, I am no longer getting a error message but I'm also not getting any output either. Do you have an idea why?

Ah, I think I see:

DESCRIPTION
     The look utility displays any lines in file which contain string as a
     prefix.  As look performs a binary search, the lines in file must be
     sorted (where sort(1) got the same options -d and/or -f that look is
     invoked with).

...so look really does need to know how long the file is.

grep should work since it doesn't, but won't have the performance advantage of being able to do a binary search.

grep '^string to find' bigfile

will find words just like look does. Minus the good performance.

Yes, the boost in performance is precisely why I need "look". hm..

Is your operating system 32-bit or 64-bit? The 64-bit version may not have the file size limit.

It's 64-bit. When I use input redirect ( < ) on a smaller test file, I get no ouput. I do get the correct output when I omit the redirect symbol.

yes... 'look' doesn't do quite what I thought it did. When you give it no input file it tries to use something in /usr/share/dict!

So no, redirection won't work in this case.

Annoying that your version of look can't support large files on a 64-bit system! This may be a bug.

---------- Post updated at 01:53 PM ---------- Previous update was at 01:46 PM ----------

Looking at the code it doesn't have an explicit built-in limit, it just uses mmap. When I have access to a 64-bit machine later today I'll see what mmap does on 64-bit systems for enormous files.

Assuming your file is sorted and has some reasonablly high H value (the leading characters change) try some kind of a radix split to get small files.

For this example assume that most of the letters of the alphabet are found as the leading character of a record and they are all uppercase. This means you can have ~26 smaller files, all of which look will work on.

awk {file=substr($0,1,1); print $0 > file}' bigfile

This will create 26 smaller files all named A, B, C ... Z. So, now your command becomes:

string="String value"
look "$string"  ${string:0:1}

${string:0:1} evalautes to the first letter of the search string, which is the file name.

I tested the "look" command on a remote server through ssh. The machine has a Darwin Kernel Version 9.8.0 (32-bit). I'm getting the same error message. "File too large". Again, thank you for all the help.

Just did some testing at home. I don't think your Linux system is actually 64-bit; I just mmaped an entire 650-gigabyte file in 64-bit Linux. Granted that was a sparse file, so I went and mapped in all of /dev/sda next.

Even if you have a 64-bit processor, you get none of the benefits unless you install a 64-bit operating system -- namely, each process is limited to 4 gigabytes of virtual memory at most on a 32-bit system.

Naturally 32-bit OSX would have this limit too. Changing the OS without changing the number of bits won't give you more address space.

Try cat /proc/version

Result of cat /proc/version :

Linux version 2.6.35-28-generic (buildd@allspice) (gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) ) #50-Ubuntu SMP Fri Mar 18 18:42:20 UTC 2011

I knew I needed a 64-bit system, so I installed the 64-bit version in advance.

When I try "uname -a", I get:
Linux patrick-G53JW 2.6.35-28-generic #50-Ubuntu SMP Fri Mar 18 18:42:20 UTC 2011 x86_64 GNU/Linux

Are there other issues that could have been overlooked thus far?

Then perhaps Ubuntu's saddled you with a 32-bit look for some reason. file /usr/bin/look

To get "look" to work with large files larger than 2^31 - 1 you'll have to get the source and apply a patch.

(Doh! I can't post links, not enough karma. Grr.. You'll have to unobfuscate the urls, Mods? help please)

Per this bug report

Bugs : Ubuntu+source/bsdmainutils/+bug/510613

This is the package that provides "look"

packages.debian.org/wheezy/bsdmainutils

Dowload the source

ftp.de.debian.org/debian/pool/main/b/bsdmainutils/bsdmainutils_8.2.2.tar.gz

Unpack it
tar zxf bsdmainutils_8.2.2.tar.gz

Get this patch from the bug report

Bugs : Ubuntu+source/bsdmainutils/+bug/510613/+attachment/2146461/+files/look2.diff

Apply the patch to get 2G files to work (from bug report)
cd bsdmainutils-8.2.2
patch -p1 <look2.diff

Apply the patch included with the package (to get the -b switch)
patch -p1 <debian/patches/look_bflag.diff

Compile
gcc usr.bin/look/look.c -o look