Operating System - HP-UX
1832275 Members
1844 Online
110041 Solutions
New Discussion

how to reduce a large file

 
SOLVED
Go to solution
Ignacio Rodríguez Arrós
Frequent Advisor

how to reduce a large file

I have a 55Mg file in oracle (alert_baan.log) and i want to reduce it by supressing the 1000000 first lines.Witch command must i used?
(Sorry for my english, i hope you'll understand it)
13 REPLIES 13
Steve Steel
Honored Contributor

Re: how to reduce a large file

Hi

Copy it to another name and then use
tail +n 1000001 newfile > oldfile
rm newfile


see man tail


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Pierce Byrne_1
Frequent Advisor

Re: how to reduce a large file

tail +100000 file > file.new
mv file.new file
Stefan Farrelly
Honored Contributor
Solution

Re: how to reduce a large file


The alert log is constantly being help open/possibly written to so I dont think you want to rm it. Simply null it out by doing;
cat /dev/null >alert_baan.log

This will make the logfile 0 bytes in size but not remove it so that any running processes using this logfile can still use it.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Ravi_8
Honored Contributor

Re: how to reduce a large file

Hi

#tail +n 1000000 file > newfile
#mv newfile file

should do the job
never give up
James Beamish-White
Trusted Contributor

Re: how to reduce a large file

Hiya,

Yes, the commands (as stated above) are:

tail +1000000 alert_baan.log > myfile
mv myfile alert_baan.log

I would put it in a script so as to minimise the time between commands, otherwise you might overwrite some logs that are added to the end of the original file before you mv the new file over it.

Cheers!
James
GARDENOFEDEN> create light
Kenneth_19
Trusted Contributor

Re: how to reduce a large file

This method also works:

# sed -n '1000000,$ p' alert_baan.log > new_file
# mv new_file alert_baan.log

Regards,
Kenneth

Always take care of your dearest before it is too late
Justo Exposito
Esteemed Contributor

Re: how to reduce a large file

Hi Ignacio,

You can do it by using ed, in order to do it try this:
echo "1, 1000000 d\nw" | ed alert_baan.log

Hope this helps you,

Justo.

Deber??as adjudicar puntos a las soluciones que te dan, esas son las reglas y recomendaciones del foro y si no lo haces podr??as dejar de obtener ayuda.
Help is a Beatiful word
Bill McNAMARA_1
Honored Contributor

Re: how to reduce a large file

split has a line option also, and can be useful for large file operations..

Later,
Bill
It works for me (tm)
Ignacio Rodríguez Arrós
Frequent Advisor

Re: how to reduce a large file

Justo, he entrado a ver las respuestas 4 veces y las cuatro veces he asignado puntos, luego pincho en submit, espero a que salga la siguiente pantalla y cierro el explorador, pero he observado que cuando vuelvo a entrar, los punto no aparecen, sigue a pareciendo el boton para asignarlos. Lo siento pero no se lo que hago mal para que no aparezcan. Si me indicais c??mo hacerlo correctamente vuelvo a a signarlos. A Y gracias a todos, todas las soluciones son validas aunque he usado la de cat /dev/nul >
Nick Wickens
Respected Contributor

Re: how to reduce a large file

I use csplit to housekeep log files - Attached is a script I use which maintains only the last few weeks of my aplications log directories. Because the application does not write a regular datestamp in the log I force one by running this everynight at midnight.

ERRORLOG=/opt/ROBIN/log
for LOGNAME in $(ls $ERRORLOG | grep rerr)
do
date +Logday=%.1j >> $ERRORLOG/$LOGNAME
done

The script attached is then run 30 minutes later.
Hats ? We don't need no stinkin' hats !!
Nick Wickens
Respected Contributor

Re: how to reduce a large file

Translation courtesy of altavista

Just, I have entered to see the answers 4 times and the four times I have assigned points, soon thorn in submit, hope to that it leaves the following screen and I close the explorer, but have observed that when I return to enter, them point do not appear, follows seeming the button to assign them. I feel it but not what I make bad so that they do not appear. If me indicais how to do it correctly I return to a to sign them. To and thanks to all, all the solutions are been worth although I have used the one of cat/dev/nul >
Hats ? We don't need no stinkin' hats !!
Nick Wickens
Respected Contributor

Re: how to reduce a large file

Heres the script that failed to attach earlier (hopefully !)
Hats ? We don't need no stinkin' hats !!
Nick Wickens
Respected Contributor

Re: how to reduce a large file

Ok third time lucky - heres the script (please please please appear this time !)
Hats ? We don't need no stinkin' hats !!