Operating System - HP-UX
1752801 Members
5653 Online
108789 Solutions
New Discussion юеВ

Re: How to split a large file

 
Unix Administrator_9
Occasional Contributor

How to split a large file

Hi,

I'm looking for a way I can split an Oracle alert log based on month. Currently I go into vi, create a new file with the data required, and then purge out of the current alert log. I've currently got an alert log which is about 420Mb in size. I would like to be able to delete all lines upto, say 1/8/04.

Any suggestions?

TIA,
Scott Taylor.
11 REPLIES 11
Stefan Schulz
Honored Contributor

Re: How to split a large file

Hi,

for splitting a file based on expressions have a look at csplit. This will allow you to split the log file based on Dates in this file.

For deleting up to an date i would use perl. this is flexible and capable of handling large files.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Sanjay Kumar Suri
Honored Contributor

Re: How to split a large file

No straight way.

Find out the line number from where you want to keep the alert log. Then use tail command

tail -nline_number alert_log>new_alert_log
mv alert_log old_alert_log
mv new_alert_log alert_log

sks

A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Ramalingam
Advisor

Re: How to split a large file

Hi ,
You can try 'csplit' with regexpression
You can scan for a regex then delete all lines preceding it ..

csplit /regex/+

See man csplit
HTH
Regards,
Ram.
We Learn the most When We have to Invent
Franky_1
Respected Contributor

Re: How to split a large file

Hi Scott,

basically you can split up a large file with the equally named "split" command where you can determine the size of the pieces by your own.
In your special case you can use
vi
:set number (show line numbering)
then search the first line you want to keep (eg. 120000)
then type 1G (top of file) and type 120000dd
this will delete the first 120000 lines and let you just the rest you want to keep.
Maybe there are better solutions, but at least it works :-)

Regards

Franky
Don't worry be happy
Ravi_8
Honored Contributor

Re: How to split a large file

Hi Scott

open the log file using vi
:setnu
assign the numbers to each line, check for the lines upto 1/8/04 (note the line number)

spilt -l
never give up
Thierry Poels_1
Honored Contributor

Re: How to split a large file

hi,

how to split the alert file by month? Simple: start a cronjob each first or last minute of the month and move the file.

Personally I cut off the first n lines when the alert file exceeds a specified size.

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Muthukumar_5
Honored Contributor

Re: How to split a large file

we can do it simply with sed as,

To get this month informations,

sed -e ,!d org-file >> backupfile

To purge that details from original files,

echo "`sed -e ,d org-file`" > org-file

-- muthu --
Easy to suggest when don't know about the problem!
V. Nyga
Honored Contributor

Re: How to split a large file

Hi Scott,

for me cat (or more) works:
cat "alert log" | grep "string defining your month" > "new file"

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Kent Ostby
Honored Contributor

Re: How to split a large file

Scott --

You can use awk as well to do something like this (although awk has a limit to the max fields per line that can sometimes mess you up).

If you post the layout of the file (say a few sample lines) so I can see what the date string looks like, I could probably whip up a script in short order.

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"