Welcome, Guest: Join Kenyans247 Log In!

Stats: 252 Members, 12,668 topics and 65 posts Date:  Monday 25 May 2020 at 09:37 PM
Popular & Trending NewestFeatured Links ClassifiedDirectoryLivescoresLive Kenyan TVLive Kenyan Radio Follow Us Like Us

About Us Terms & Conditions Privacy Policy FAQ's Disclaimer Copyright Contact Us Advertise With Us Download K247 APP Marketplace Moderator Policy We Are Hiring Kenya Radio and TV Stations Listen and Watch Live Letter From the C.E.O Kenya Radio Stations Live Kenya TV Stations Live Kenya - Newspapers and News Sites and popular blog Forum Rules

Split a text file in half (or any percentage) on Ubuntu Linux

Kenyans247 / Science/Technology / Computers / Split a text file in half (or any percentage) on Ubuntu Linux

49 people viewed

How To Scrape Text From An Image In Chrome Split A Text File In Half (or Any Percentage) On Ubuntu Linux
(Go Down) (» Reply topic)
Split a text file in half (or any percentage) on Ubuntu Linux by Kenyans247(1): Sun 22, March, 2020 10:26am
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.

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

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.

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

> wc -l access.log
146330 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.

> split -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

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:

> split -l 73165 access.log

And, that’s all there is to it.

0 Shares 0 Like •

(» Go Up)

You must Sign in or Sign Up to post content

For you to post content on this website you have to log in or register, it only take few minute to create account

Go Up

Recommended for you

Split A Text File In Half (or Any Percentage) On Ubuntu Linux How To Scrape Text From An Image In Chrome

Currently: 1 guest(s) reading this article

Sections: Kenyans247 ads, Homepage, Africa, International Forum, Pets, Technology Market, Innovation, Programing, Universities, Education, Gossip, Social Media/K247 Chit-Chat, Poetry, Lifestyle, Jokes Etc, South Sudan Forum, Rwanda Forum, Burundi Forum, Ugandan Forum, Tanzania Forum,

About Us | Terms & Conditions | Privacy Policy | FAQ's | Disclaimer | Copyright | Contact Us | Advertise With Us | Download K247 APP | Marketplace | Moderator Policy | We Are Hiring | Kenya Radio and TV Stations Listen and Watch Live | Letter From the C.E.O | Kenya Radio Stations Live | Kenya TV Stations Live | Kenya - Newspapers and News Sites and popular blog | Forum Rules | Featured LinksFollow Us on TwitterLike Us on Facebook

Kenyans247 - Copyright © 2019 - 2020 Sande Kennedy. All rights reserved. See How To Advertise.
Disclaimer: Every Kenyans247 member is solely responsible for anything that he/she posts or uploads on Kenyans247.