Opening Large Log Files in Unix

How to open or view large log files in unix. vi editor complains of the file being too large to open.

---->
If you don't need to modify the file, you can use 'more'
Read 'more' man page.

---->
This script will pull a chunk of lines from a file into a workfile and invoke vi on the workfile.

#!/bin/sh
#
# viewpart
#
# Usage: viewpart filename starting_line [ # ]
#
# Without # of lines, remainder of file is taken.

if [ $# -ne 2 -a $# -ne 3 ] ; then
???echo '\nUsage: viewpart filename starting_line [ # ]\n'
???exit 1
fi

fname=$1
start=$2
lines=$3

if [ ! -r $fname ] ; then
???echo "Cannot read $fname"
???exit 1
fi

workfile=/tmp/viewpart$$

if [ "$lines" ] ; then
???tail +$start $fname | head -$lines > $workfile
else
???tail +$start $fname > $workfile
fi

vi $workfile

echo "\nRemove workfile $workfile ? [yn] \c"
read answer

if [ "$answer" = y ] ; then
???rm -f $workfile
???echo "\n$workfile removed\n"
else
???echo "\n$workfile NOT removed\n"
fi

exit 0

---->
Many implementations of vi set the dir value to /var/tmp. This is ok if /var/tmp is a large filesystem. However, many times it is not. To change it to /tmp (or some other large filesystem), open the editor by typing:
vi

While in the vi editor, type the command:

:set dir

This will display the directory where vi is opening files. If it is pointing to a small filesystem, type the command:

:set dir=/tmp (or other large filesystem)

You can now open the file by typing:

:r <filename>

Don't use the angle brackets around filename, it's just to highlight the syntax.

The options previously proposed are good ones and the script looks nice. This is just a "FYI" regarding temp files in vi.

If you need to set these everytime you open vi then create a .exrc file. The file will read:

set dir=/tmp

Set the ownership of the file so others cannot change it. Commands can be placed in the .exrc file and will execute when vi is invoked. This is not a good thing if you are root. It can be used to do interesting things.

See Also
Unix Administrator Career Path

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.