Subscribe to How-To Geek सदस्यता के लिए कैसे करने के लिए geek -

Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Split a text file in half (or any percentage) on Ubuntu Linux भाजित छमाही में एक पाठ फ़ाइल (या कोई प्रतिशत Ubuntu Linux पर)

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. विभाजन दर्ज करें, WC पूंछ, बिल्ली, और grep. (don't forget sed and awk). कर (और sed नहीं awk) भूल जाओ. Linux contains a rich set of utilities for working with text files on the command line. Linux कमांड लाइन पर पाठ फ़ाइलों के साथ काम करने के लिए उपयोगिताओं के एक अमीर सेट होता है. For our task today we will use split and wc. हमारे काम के लिए आज हम विभाजन और WC प्रयोग करेंगे.

First we take a look at our log file…. पहले हम हमारे लॉग फाइल को देखो ....

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

We see that the file size is 42MB. हम देखते हैं कि फ़ाइल आकार 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. यदि हम एक्सेल में यह आयात करना चाहता था, हम उसे कम से कम 65k लाइनों रखने की आवश्यकता होगी.

Let's check the amount of lines in the file using the wc utility, which stands for “word count”. चलो फ़ाइल में लाइनों की मात्रा की जांच WC उपयोगिता है, जो 'के लिए शब्द गणना का उपयोग कर खड़ा है. "

> wc -l access.log > WC-L access.log
146330 access.log 146,330 access.log

We're way over our limit. हम अपनी सीमा के रास्ते पर हैं. We'll need to split this into 3 segments. हम से 3 क्षेत्रों में इस विभाजन की आवश्यकता होगी. We'll use the split utility to do this. हम अलग उपयोगिता का प्रयोग कर यह कर दूँगा.

> split -l 60000 access.log > विभाजन एल 60,000 access.log
> ls -l रास>-L

total 79124 कुल 79,124
-rw-rw-r– 1 thegeek ggroup 40465200 2006-09-19 12:00 access.log rw-rw-r-1 ggroup thegeek 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 ggroup thegeek 16598163 2006-09-19 12:05 xaa
-rw-rw-r– 1 thegeek ggroup 16596545 2006-09-19 12:05 xab rw-rw-r-1 ggroup thegeek 16596545 2006-09-19 12:05 xab
-rw-rw-r– 1 thegeek ggroup 7270492 2006-09-19 12:05 xac rw-rw-r-1 ggroup thegeek 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. अब हम अलग 3 फ़ाइलें, हमारे पाठ फ़ाइलों में विभाजित है कम से कम 60,000 लाइनों, जो कि एक अच्छी संख्या में चुनाव की तरह लग रहा था जिसमें प्रत्येक. 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 > विभाजन एल 73,165 access.log

And, that's all there is to it. और, यह सब वहाँ यह है.

This article was originally written on 09/19/06 Tagged with: यह आलेख मूल रूप से 09/19/06 टैग पर लिखा था: Shell Scripts खोल लिपियों , , Ubuntu Ubuntu

Daily Email Updates दैनिक ईमेल अपडेट

You can get our how-to articles in your inbox each day for free. आप अपने इनबॉक्स में हमारे कैसे लेख को मुफ्त के लिए प्रत्येक दिन प्राप्त कर सकते हैं. Just enter your name and email below: बस नीचे अपना नाम और ईमेल दर्ज करें:


Name: नाम:
Email: ईमेल:

Comments (1) टिप्पणियाँ (1)

  1. Simon C. Ion शमौन सी. आयन

    If you have bc and sed installed, why not do this to calculate the halfway point of the file and perform the split? यदि आप और ई.पू. है sed स्थापित है, तो क्यों नहीं इस फाइल के आधे रास्ते बिंदु की गणना और विभाजन का पालन नहीं?

    split -l $(echo $(cat tmp.txt | wc -l)/2 | bc -l | sed -e 's/\..*//') access.log विभाजन एल ($ $ (बिल्ली tmp.txt प्रतिध्वनि |-l) / 2 | ई.पू. एल WC sed |-ए 's / \ ..*//') access.log

    NB: bc seems to default to a floating-point output. एनबी: ई.पू. एक चल बिन्दु उत्पादन के लिए डिफ़ॉल्ट लगता है. The sed invocation effectively act as a call to floor(3), stripping away the numbers after the decimal, and making my version of split happy. Sed मंगलाचरण प्रभावी ढंग से (3) मंजिल पर एक फोन के रूप में कार्य, दशमलव के बाद दूर अलग करना नंबर, और खुश विभाजन के अपने संस्करण बना. I guess that the sed expression would need to be changed to 's/,.*//' for locales that use ',' as their “numbers after the decimal” indicator. मुझे लगता है कि sed अभिव्यक्ति के लिए 'में परिवर्तित करने की आवश्यकता होगी स्थलों के लिए /,.*//' एस कि' उपयोग करते हैं, 'के रूप में उनके दशमलव सूचक "के बाद" संख्या.


Leave a Comment एक टिप्पणी छोड़ दो




Leave your छोड़ अपने friendly मित्र comment here. यहाँ टिप्पणी नहीं.

If you have a computer help question, यदि आप एक कंप्यूटर की मदद सवाल है, click here to leave it on the forums यहाँ क्लिक करें यह मंचों पर जाने के लिए instead. बजाय.

Note: Your comment may not show up immediately on the site. ध्यान दें: आपकी टिप्पणी को तुरंत नहीं दिखा साइट पर कर सकते हैं.

Our Friends हमारे दोस्त
Getting Started प्रारंभ करना


About How-To Geek के बारे में कैसे करने के लिए geek -
What Is That Process? यह प्रक्रिया क्या है?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
mDNSResponder.exe mDNSResponder.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. कॉपीराइट © HowToGeek.com 2006-2009. All Rights Reserved. सर्वाधिकार सुरक्षित.