Cutting a large log file in to smaller ones


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting a large log file in to smaller ones
# 1  
Old 05-17-2004
Cutting a large log file in to smaller ones

I have a very large (150 megs) IRC log file from 2000-2001 which I want to cut down to individual daily log files. I have a very basic knowledge of the cat, sed and grep commands. The log file is time stamped and each day in the large log file begins with a "Session Start" string like so:

Session Start: Tue Mar 21 03:54:00 2000

Any idea how I could take this large log file, and use sed/grep to break it up in to individual daily versions? Ideally the output would save in to a directory of my chosing in sequential format. Something like so: "resultingfile001.log" and "resultingfile002.log" and so on. I will manually rename the files afterwards.

Any and all help would be greatly appreciated!
# 2  
Old 05-17-2004
I would suggest using awk...
Code:
awk '
/Session Start:/ {
  close f
  ++n
}
{
  f=sprintf("resultingfile.%03d",n)
  print $0 > f
}
' largelogfile

# 3  
Old 05-17-2004
split and dd will also do what you need.

Carriage-control files work the best with split. IMO.
# 4  
Old 05-17-2004
Quote:
Originally posted by jim mcnamara
split and dd will also do what you need.
How? Have you got an example? I didn't know that split or dd could search files for a particular pattern. My versions of split and dd can only break-up a file into fixed-size pieces.
# 5  
Old 05-17-2004
My bad.

They are modified versions of dd and split. They accept '-exec ' like arguments -- it allows us to embed commands like 'grep -l' which return multiple line numbers.

We reformat huge numbers of files and convert between ASCII-EBCDIC, so a decision was made a long time ago to do it this way.
# 6  
Old 05-17-2004
Quote:
Originally posted by Ygor
I would suggest using awk...
Code:
awk '
/Session Start:/ {
  close f
  ++n
}
{
  f=sprintf("resultingfile.%03d",n)
  print $0 > f
}
' largelogfile

I appreciate everyone's follow-ups. I tried using this code, dumped it in to a shell script, chmod'ed it and tried running it. There seems to be a problem, however. It gave me one "resultingfile.001" but stopped afterwards. Any pointers? Otherwise it appears it will do exactly what I need it to!

Thank you very much for your help, Ygor!
# 7  
Old 05-18-2004
Perhaps you using an old version of awk? On some systems the newer awk is called nawk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split large file into smaller files without disturbing the entry chunks

Dears, Need you help with the below file manipulation. I want to split the file into 8 smaller files but without cutting/disturbing the entries (meaning every small file should start with a entry and end with an empty line). It will be helpful if you can provide a one liner command for this... (12 Replies)
Discussion started by: Kamesh G
12 Replies

2. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

3. UNIX for Dummies Questions & Answers

Split large file to smaller fastly

hi , I have a requirement input file: 1 1111111111111 108 1 1111111111111 109 1 1111111111111 109 1 1111111111111 110 1 1111111111111 111 1 1111111111111 111 1 1111111111111 111 1 1111111111111 112 1 1111111111111 112 1 1111111111111 112 The output should be, (19 Replies)
Discussion started by: mechvijays
19 Replies

4. Shell Programming and Scripting

Sed: Splitting A large File into smaller files based on recursive Regular Expression match

I will simplify the explaination a bit, I need to parse through a 87m file - I have a single text file in the form of : <NAME>house........ SOMETEXT SOMETEXT SOMETEXT . . . . </script> MORETEXT MORETEXT . . . (6 Replies)
Discussion started by: sumguy
6 Replies

5. Shell Programming and Scripting

Help needed - Split large file into smaller files based on pattern match

Help needed urgently please. I have a large file - a few hundred thousand lines. Sample CP START ACCOUNT 1234556 name 1 CP END ACCOUNT CP START ACCOUNT 2224444 name 1 CP END ACCOUNT CP START ACCOUNT 333344444 name 1 CP END ACCOUNT I need to split this file each time "CP START... (7 Replies)
Discussion started by: frustrated1
7 Replies

6. Shell Programming and Scripting

Split large file into smaller file

hi Guys i need some help here.. i have a file which has > 800,000 lines in it. I need to split this file into smaller files with 25000 lines each. please help thanks (1 Reply)
Discussion started by: sitaldip
1 Replies

7. UNIX for Dummies Questions & Answers

multiple smaller files from one large file

I have a file with a simple list of ids. 750,000 rows. I have to break it down into multiple 50,000 row files to submit in a batch process.. Is there an easy script I could write to accomplish this task? (2 Replies)
Discussion started by: rtroscianecki
2 Replies

8. Shell Programming and Scripting

Help with splitting a large text file into smaller ones

Hi Everyone, I am using a centos 5.2 server as an sflow log collector on my network. Currently I am using inmons free sflowtool to collect the packets sent by my switches. I have a bash script running on an infinate loop to stop and start the log collection at set intervals - currently one... (2 Replies)
Discussion started by: lord_butler
2 Replies

9. UNIX for Dummies Questions & Answers

splitting the large file into smaller files

hi all im new to this forum..excuse me if anythng wrong. I have a file containing 600 MB data in that. when i do parse the data in perl program im getting out of memory error. so iam planning to split the file into smaller files and process one by one. can any one tell me what is the code... (1 Reply)
Discussion started by: vsnreddy
1 Replies

10. UNIX for Dummies Questions & Answers

Need help cutting a couple of fields from log file.

Data begins as such; Mar 16 03:27:05 afzpimdn01 named: denied update from .3983 for "nnn.nnn.in-addr.arpa" IN Mar 16 03:27:37 afzpimdn01 named: denied update from .4844 for "nnn.nnn.in-addr.arpa" IN Mar 16 03:27:56 afzpimdn01 named: denied update from .2650 for "nnn.nnn.in-addr.arpa" IN ... (4 Replies)
Discussion started by: altamaha
4 Replies
Login or Register to Ask a Question