Use shell scripts to split large files

Source: Internet
Author: User
In the process of system O & M, log files are often very large. In this case, we need to split the log files. Here, we use shell scripts to split the files :#! /Bin/bash



Linenum = 'wc-l httperr8007.log | awk '{print $1 }''

N1 = 1

File = 1

While [$ N1-lt $ linenum]

Do

N2 = 'expr $ N1 + 100'

Sed-n "$ {N1}, $ {N2} p" httperr8007.log> file _ $ file. Log

N1 = 'expr $ N2 + 1'

File = 'expr $ file + 1'

Done
Here, httperr8007.log is the big file you want to split. File _ $ file. log is the split file, and file_1.log, file_2.log, file_3.log ......, Each split file contains only 1000 lines (you can set the parameters yourself). Method 2: Split parameter:

-B: the size of the file to be split. The unit can be added, for example, B, K, and M;

-L: split by the number of lines; # split by 1000 lines of each file except for the split-l 1000 httperr8007.log httperr httpaa, httpab, httpac ........ # split the split-B 100 k According to KB of each file. httperr8007.log HTTP httpaa, httpab, httpac ........
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.