How to remove file entries without vi or > null

  • Follow


Hi all,

We are using BEA Weblogic to run Web-Based system. A file call
access.log will be generated once weblogic start.

The problem the file had been bigger to 2 GB. I am not able to vi the
file delete some of the few entries or even more the files, it seems
took forever. I managed to ftp to my laptop but still could not open
and getting "Not Enough Memory error" . I need to maintain last 7 days
logs. How do i delete the rest of line without vi ? And to null > the
files is only last option.

Thanks.

-pooga-

0
Reply pooganesan (2) 7/12/2007 3:17:20 AM

pooga wrote:
> Hi all,
> 
> We are using BEA Weblogic to run Web-Based system. A file call
> access.log will be generated once weblogic start.
> 
> The problem the file had been bigger to 2 GB. I am not able to vi the
> file delete some of the few entries or even more the files, it seems
> took forever. I managed to ftp to my laptop but still could not open
> and getting "Not Enough Memory error" . I need to maintain last 7 days
> logs. How do i delete the rest of line without vi ? And to null > the
> files is only last option.
> 
> Thanks.
> 
> -pooga-
> 
Try this:
tail -100 access.log > newfile
100 is an example, it shows the last 100 lines of your file.
But maybe you need 10000 lines.
You can remove the acces.log and rename newfile to access.log
0
Reply DevN0ll 7/12/2007 9:24:04 AM


pooga wrote:
> Hi all,
> 
> We are using BEA Weblogic to run Web-Based system. A file call
> access.log will be generated once weblogic start.
> 
> The problem the file had been bigger to 2 GB. I am not able to vi the
> file delete some of the few entries or even more the files, it seems
> took forever. I managed to ftp to my laptop but still could not open
> and getting "Not Enough Memory error" . I need to maintain last 7 days
> logs. How do i delete the rest of line without vi ? And to null > the
> files is only last option.

awk is your friend.

user tail and head to look for patterns. There are sure some datestamp
on each row. The do something like this (ugly but quick)



awk '!/Jul 12/' /weblogic/access.log > /weblogic/access.log.old
awk '/Jul 12/' /weblogic/access.log > /weblogic/access.log.new
cp /weblogic/access.log.new /weblogic/access.log
0
Reply Thommy 7/12/2007 9:25:04 AM

On Jul 12, 5:17 am, pooga <poogane...@gmail.com> wrote:
> Hi all,
>
> We are using BEA Weblogic to run Web-Based system. A file call
> access.log will be generated once weblogic start.
>
> The problem the file had been bigger to 2 GB. I am not able to vi the
> file delete some of the few entries or even more the files, it seems
> took forever. I managed to ftp to my laptop but still could not open
> and getting "Not Enough Memory error" . I need to maintain last 7 days
> logs. How do i delete the rest of line without vi ? And to null > the
> files is only last option.
>
> Thanks.
>
> -pooga-

Well you could  keep generations of the file like this.

---------------------

mv  file006.log  fill007.log
mv file005.log file006.log
mv file004.log file005.log
mv file003.log  file004.log
mv file002.log fille003.log
mv file001.log file002.log
cp  activefile.log  file001.log
> activefile.log

------------------------------

if you run a script  like  the above  with the filenames of you
choise , once  every day ,
probably from CRON ,  the files would not become so huge.

Its important not to move the active logfile but to copy it.  so that
the Inode number
remains the same for the applikation .

//Lars

0
Reply tunla 7/12/2007 9:26:53 AM

"Thommy M." <thommy.m.malmstrom@gmail.com> wrote in message news:Qrmli.3955$ZA.1945@newsb.telia.net...
> pooga wrote:
> > Hi all,
> >
> > We are using BEA Weblogic to run Web-Based system. A file call
> > access.log will be generated once weblogic start.
> >
> > The problem the file had been bigger to 2 GB. I am not able to vi the
> > file delete some of the few entries or even more the files, it seems
> > took forever. I managed to ftp to my laptop but still could not open
> > and getting "Not Enough Memory error" . I need to maintain last 7 days
> > logs. How do i delete the rest of line without vi ? And to null > the
> > files is only last option.
>
> awk is your friend.
>
> user tail and head to look for patterns. There are sure some datestamp
> on each row. The do something like this (ugly but quick)
>
>
>
> awk '!/Jul 12/' /weblogic/access.log > /weblogic/access.log.old
> awk '/Jul 12/' /weblogic/access.log > /weblogic/access.log.new
> cp /weblogic/access.log.new /weblogic/access.log

In the longer term, set up log rotation so you get a different
log file each day or week or 500 megabytes or whatever.

There are several different ways of doing this, and it depends
slightly on which versions of Weblogic and Solaris you are using.
Read the manuals, check the support sites or search the web.

-- 
John.


0
Reply John 7/12/2007 12:32:29 PM

On Wed, 11 Jul 2007 20:17:20 -0700, pooga <pooganesan@gmail.com> wrote:
> Hi all,
> We are using BEA Weblogic to run Web-Based system. A file call
> access.log will be generated once weblogic start.
>
> The problem the file had been bigger to 2 GB. I am not able to
> vi the file delete some of the few entries or even more the
> files, it seems took forever. I managed to ftp to my laptop but
> still could not open and getting "Not Enough Memory error" . I
> need to maintain last 7 days logs. How do i delete the rest of
> line without vi ? And to null > the files is only last option.

A 'stream editor' is more useful for this sort of thing.

If the file includes date/time information in each line, you can
filter the timestamps with something like:

    awk '{print $1,$2}' hugefile | uniq

then, when you locate the date/time that interests you, it should
be trivial to use `cat' with its -n option to find out the
precise line-range you are interested in, and filter the file
once more through `sed' to delete the first part of the file.

A lot of people know sed's ability to "substitute strings", but
that's not all sed can do.  For example, see the output below:

kobe % wc -l /var/log/messages
     413 /var/log/messages
kobe % sed -e '1,410d' /var/log/messages
Jul 13 12:24:23 kobe sudo: keramida : TTY=pts/22 ; PWD=/home/ftp/distfiles ; USER=root ; COMMAND=/usr/bin/fetch http://ftp.gnu.org/gnu/libtool/libtool-1.5.24.tar.gz
Jul 13 12:51:48 kobe named[1690]: client 127.0.0.1#63509: RFC 1918 response from Internet for 180.1.8.10.in-addr.arpa
Jul 13 14:39:46 kobe su: keramida to root on /dev/pts/2
kobe % 

0
Reply Giorgos 7/13/2007 11:47:27 AM

5 Replies
492 Views

(page loaded in 0.091 seconds)

Similiar Articles:













7/27/2012 10:17:01 AM


Reply: