Split FILE command instance in CentOS

Source: Internet
Author: User

Split FILE command instance in CentOS

Have you ever wanted to split a large file into multiple small files? For example, a 5 GB log file needs to be divided into multiple small files so that we can use a common text editor to read it. Sometimes we need to transfer 20 GB of large files to another server, which requires us to split it into multiple files to facilitate data transmission. Next we will explain it through five instances.

Instance 1, separated by 1000 lines per file

The split command splits the file into 1000 lines for each file, and the file names are in turn [prefix] aa, [prefix] AB, [prefix] ac, etc. The default prefix is X, the number of lines in each file is 1000. The command is as follows:

  1. $ Split mylog
  2. $ Wc-l *
  3. 4450 mylog
  4. 1000 xaa
  5. 1000 xab
  6. 1000 xac
  7. 1000 xad
  8. 450 xae
Instance 2, separated by 20 mb for each file

Split the file into multiple 20 mb files with the-B Option command as follows:

  1. $ Split-B 20 M logdata
  2. $ Ls-lh | tail-n + 2
  3. -Rw ------- 1 sathiya 102 M Jul 25 logdata
  4. -Rw ------- 1 sathiya 20 M Jul 25 19:20 xaa
  5. -Rw ------- 1 sathiya 20 M Jul 25 19:20 xab
  6. -Rw ------- 1 sathiya 20 M Jul 25 :20 xac
  7. -Rw ------- 1 sathiya 20 M Jul 25 19:20 xad
  8. -Rw ------- 1 sathiya 20 M Jul 25 19:20 xae
  9. -Rw ------- 1 sathiya 1.6 M Jul 25 xaf
Instance 3, separated by a specified prefix of 50 MB for each file

Use the -- bytes option to split the file into multiple 50 MB files. -- bytes is similar to the-B option and specifies the prefix in the second parameter.

  1. $ Split -- bytes = 50 M logdata mydatafile
  2. $ Ls-lh
  3. Total 204 M
  4. -Rw ------- 1 sathiya 102 M Jul 25 logdata
  5. -Rw ------- 1 sathiya 50 M Jul 25 :23 mydatafileaa
  6. -Rw ------- 1 sathiya 50 M Jul 25 19:23 mydatafileab
  7. -Rw ------- 1 sathiya 1.6 M Jul 25 mydatafileac
Instance 4. Split files based on the number of lines

Use the-l option to specify the number of lines to split the file into multiple files with the same number of lines.

  1. $ Wc-l testfile
  2. 2591 testfile
  3. $ Split-l 1500 testfile importantlog
  4. $ Wc-l *
  5. 1500 importantlogaa
  6. 1091 importantlogab
  7. 2591 testfile
Instance 5. Split the file with a digital suffix

You can use the-d option to specify the suffix as a number, for example, 02..., instead of aa, AB, and ac.

  1. $ Split-d testfile
  2. $ Ls
  3. Testfile x00 x01 x02
Available optionsShort option long option description-B -- bytes = SIZESIZE value is the size of each output file, in bytes. -C -- line-bytes = SIZE: Maximum number of bytes in a single row in each output file. -D -- numeric-suffixes uses numbers as suffixes. -L -- lines = NUMBERNUMBER indicates the number of columns in each output file.

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.