Prenumerera till Hur-Till 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.

Dela en text sparar i halva (eller någon procentsats) på Ubuntu Linux

Om du har en otymplig text att spara att du är pröva att bearbeta och att dela den delar upp in kan ibland hjälpa att bearbeta tid, om speciellt vi gick till importen en spara in i ett räkneark. Eller som du önskar styrkan precis att hämta en särskild uppsättning av fodrar från en spara.

Skriv in splittring, wc, svanen, katten och grep. (inte glöm sed och awk). Linux innehåller en rik uppsättning av hjälpmedel för arbete med text sparar på befalla fodrar. För vår uppgift i dag ska vi brukssplittring och wc.

Först tar vi en look på vårt loggar sparar….,

> ls - l
- thegeekggroup 42046520 2006-09-19 11:42 access.log för rw-r-r- 1

Vi ser att spara storleksanpassar är 42MB. Det är sorten av stort…, men hur många fodrar är oss som handlar med? Om vi önskade till importen denna in i Excel, skulle vi den behovsuppehället det mindre, än 65k fodrar.

Låt oss kontrollera beloppet av fodrar i spara genom att använda den nytto- wcen, som står för ”ordräkning”.

> wc - l access.log
146330 access.log

Vi är över vårt begränsar långt. Vi ska behov att dela detta in i 3 segmenterar. Vi ska bruk den nytto- splittringen att göra detta.

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

slutsumma 79124
- thegeekggroup 40465200 2006-09-19 12:00 access.log för rw-rw-r- 1
- för thegeekggroup 16598163 2006-09-19 12:05 för rw-rw-r- 1 xaa
- för thegeekggroup 16596545 2006-09-19 12:05 för rw-rw-r- 1 xab
- för thegeekggroup 7270492 2006-09-19 12:05 för rw-rw-r- 1 xac

Vi har nu delat vår text sparar in i separata 3 sparar, varje som mer mindre innehåller, än 60000 fodrar, som verkade lika en goda numrerar för att välja. Jumbon sparar innehåller det restra beloppet. Om du gick att klippa denna detalj, spara i halvan, dig skulle har gjort detta:

> splittring - l 73165 access.log

And, that’s all there is to it.

| More
This article was originally written on 09/19/06 Tagged with: Shell Scripts, 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. 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?

    split -l $(echo $(cat tmp.txt | wc -l)/2 | bc -l | sed -e ’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. I guess that the sed expression would need to be changed to ’s/,.*//’ for locales that use ‘,’ as their “numbers after the decimal” indicator.


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
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.