ubuntu 压缩拆分_在Ubuntu Linux上将文本文件拆分为一半(或任何百分比)

本文介绍了如何在Ubuntu Linux上利用split和wc等命令行工具有效地拆分大型文本文件,以帮助提高处理速度或满足导入电子表格的行数限制。通过示例演示了如何将文件按指定行数进行分割。
摘要由CSDN通过智能技术生成
ubuntu 压缩拆分

ubuntu 压缩拆分

If you have an unwieldy text file that you are trying to process, splitting it in sections can sometimes help processing time, especially if we were going to import a file into a spreadsheet. Or you might want to just retrieve a particular set of lines from a file.

如果您要处理一个笨拙的文本文件,将其分成几部分有时可以帮助您节省时间,尤其是当我们要将文件导入电子表格时。 或者,您可能只想从文件中检索一组特定的行。

Enter split, wc, tail, cat, and grep. (don’t forget sed and awk). Linux contains a rich set of utilities for working with text files on the command line. For our task today we will use split and wc.

输入split,wc,tail,cat和grep。 (不要忘记sed和awk)。 Linux包含大量用于在命令行上处理文本文件的实用程序。 对于今天的任务,我们将使用split和wc。

First we take a look at our log file….

首先,我们看一下我们的日志文件…。

> ls -l-rw-r–r– 1 thegeek ggroup 42046520 2006-09-19 11:42 access.log

> ls -l-rw-r–r– 1 thegeek ggroup 42046520 2006-09-19 11:42 access.log

We see that the file size is 42MB. That’s kinda big… but how many lines are we dealing with? If we wanted to import this into Excel, we would need to keep it less than 65k lines.

我们看到文件大小为42MB。 有点大……但是我们要处理多少行? 如果要将其导入到Excel中,则需要使其少于65,000行。

Let’s check the amount of lines in the file using the wc utility, which stands for “word count”.

让我们使用wc实用程序检查文件中的行数,该实用程序代表“字数”。

> wc -l access.log146330 access.log

> wc -l access.log146330 access.log

We’re way over our limit. We’ll need to split this into 3 segments. We’ll use the split utility to do this.

我们超出了极限。 我们需要将其分为3个部分。 我们将使用split实用程序执行此操作。

> split -l 60000 access.log> ls -l

>拆分-l 60000 access.log> ls -l

total 79124-rw-rw-r– 1 thegeek ggroup 40465200 2006-09-19 12:00 access.log-rw-rw-r– 1 thegeek ggroup 16598163 2006-09-19 12:05 xaa-rw-rw-r– 1 thegeek ggroup 16596545 2006-09-19 12:05 xab-rw-rw-r– 1 thegeek ggroup 7270492 2006-09-19 12:05 xac

总计79124-rw-rw-r– 1 thegeek ggroup 40465200 2006-09-19 12:00 access.log-rw-rw-r– 1 thegeek ggroup 16598163 2006-09-19 12:05 xaa-rw-rw-r – 1个thegeek ggroup 16596545 2006-09-19 12:05 xab-rw-rw-r– 1个thegeek ggroup 7270492 2006-09-19 12:05 xac

We’ve now split our text files into 3 seperate files, each containing less than 60000 lines, which seemed like a good number to choose. The last file contains the leftover amount. If you were going to cut this particular file in half, you’d have done this:

现在,我们将文本文件分为3个单独的文件,每个文件少于60000行,这似乎是一个不错的选择。 最后一个文件包含剩余量。 如果您打算将该特定文件切成两半,则可以这样做:

> split -l 73165 access.log

>拆分-l 73165 access.log

And, that’s all there is to it.

而且,仅此而已。

翻译自: https://www.howtogeek.com/howto/ubuntu/split-a-text-file-in-half-or-any-percentage-on-ubuntu-linux/

ubuntu 压缩拆分

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值