Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:20:14+00:00 2026-05-27T02:20:14+00:00

I have a big log file, over 1 million lines. I need to use

  • 0

I have a big log file, over 1 million lines.
I need to use regexp to find a pattern and then start chomping down until I hit another regular expression. So I would end up with something like 1500 lines.

I know sed allows use of regexp, but can it split files? I have no experience with awk, but I think that this should allow me to do what I need. I am confused from reading the manpage though… I would appriciate some examples or even more simpler solutions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:20:14+00:00Added an answer on May 27, 2026 at 2:20 am

    In both AWK ans SED you can define a RegEx like this –

    AWK: In AWK you would notice that we haven’t written print anywhere. In AWK (which is based on pattern/action statements, print is the default action whenever the pattern statement is true. Hence the in following case, whenever the RegEx pattern is true, AWK would print it for us.

    awk '/regex1/,/regex2/' INPUT_FILE > NEW_FILE
    

    SED: In SED we use a -n option to suppress default behaviour of printing everything and use the RegEx with p to tell SED for printing specific lines.

    sed -n '/regex1/,/regex2/p' INPUT_FILE > NEW_FILE
    

    Alternatively, you can also give the following one-liner

    sed '/regex1/,/regex2/!d' INPUT_FILE > NEW_FILE
    

    Using the redirection operator > you can create a subset of your file.

    For Splitting files in AWK, if you know the Number of Records in your file (wc -l < INPUT_FILE) then you can write something like this –

    awk 'NR==2,NR==5' INPUT_FILE
    

    NR is AWK’s built-in variable that gets set to the Record’s Line Number. So if you have a file with 1500 lines and need just top 750, then you can do something like this –

    awk 'NR==1,NR==750' INPUT_FILE
    

    As mentioned earlier, you can but you don’t have to mention print with AWK. It does it for you as long as your pattern is true.

    Though with a million lines in your file, this will be a major pain. So the following AWK one-liner should do the trick.

    awk '{print >("SMALL_BATCH_OF_FILES_" int((NR+2)/3))}' BIG_INPUT_FILE
    

    This one-liner will create SMALL_BATCH_OF_FILES_ containing 3 lines each. You can set this to your comfort level. (NR+2/3)

    Execution:

    [jaypal~/Temp]$ cat BIG_INPUT_FILE 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    [jaypal~/Temp]$ awk '{print >("SMALL_BATCH_OF_FILES_" int((NR+2)/3))}' BIG_INPUT_FILE
    
    [jaypal~/Temp]$ ls -lrt SMALL*
    -rw-r--r--  1 jaypalsingh  staff  3 25 Nov 10:41 SMALL_BATCH_OF_FILES_4
    -rw-r--r--  1 jaypalsingh  staff  6 25 Nov 10:41 SMALL_BATCH_OF_FILES_3
    -rw-r--r--  1 jaypalsingh  staff  6 25 Nov 10:41 SMALL_BATCH_OF_FILES_2
    -rw-r--r--  1 jaypalsingh  staff  6 25 Nov 10:41 SMALL_BATCH_OF_FILES_1
    
    [jaypal~/Temp]$ cat SMALL_BATCH_OF_FILES_1 
    1
    2
    3
    [jaypal~/Temp]$ cat SMALL_BATCH_OF_FILES_2 
    4
    5
    6
    [jaypal~/Temp]$ cat SMALL_BATCH_OF_FILES_3
    7
    8
    9
    [jaypal~/Temp]$ cat SMALL_BATCH_OF_FILES_4
    10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really big log file (9GB -- I know I need to
I have a big log file with multiple lines separated by new line. Each
I have a big apache log file and I need to filter that and
I have a file test.log. Very big log file. It has different levels of
I have a question for you: I have a big log file and I
I have a JBoss 6 Server running which generates a big log file. Does
I have an application generating a really heavy big log file every days (~800MB
I have a log file that can get pretty big. The information in my
I have big trouble with file uploads with php. My own tests are successful
I have big problem when I am trying to deploy my app over clickonce.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.