Computing.Net > Forums > Unix > Opening large log files in unix

Opening large log files in unix

Reply to Message Icon

Original Message
Name: af_25
Date: March 3, 2004 at 17:22:41 Pacific
Subject: Opening large log files in unix
OS: windows/unix
CPU/Ram: Intel P IV / Sun Sparc
Comment:

Folks,

Would be pleased to have information on how to open or view large log files in unix. vi editor complains of the file being too large to open.

Thanks,
Anita


Report Offensive Message For Removal


Response Number 1
Name: aigles
Date: March 4, 2004 at 00:47:09 Pacific
Reply: (edit)

If you don't need to modify the file, you can use 'more'

Read 'more' man page.

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 2
Name: Jim Boothe
Date: March 4, 2004 at 08:53:06 Pacific
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: thepubba
Date: March 4, 2004 at 09:42:29 Pacific
Reply: (edit)

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.

Jerry


Report Offensive Follow Up For Removal

Response Number 4
Name: Jim Boothe
Date: March 5, 2004 at 07:47:13 Pacific
Reply: (edit)

Great info Jerry - always learning something new here!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Opening large log files in unix 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge