Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I split a text file into 70% and 30% using the split command ?

share|improve this question
    
Are you wedded to using the split command? If not, you can easily do this with straight text manipulation, certainly using perl or python. As long as the file is not too wrong, read it in to memory as a string, then split the string. If the file is too big, then more work is needed. –  Faheem Mitha Mar 28 '11 at 9:20
    
@Faheem Mitha The file is 64MB. I like the idea to use split because it is faster than writing code. I was wonder now if I specify the number of lines corresponding 70% of the file, I get a big file and a small file. Shouldn't it work ? –  Patrick Mar 28 '11 at 9:23
    
And yes.. it worked.. Should I delete the question ? –  Patrick Mar 28 '11 at 9:29
    
Up to you, but not necessary. –  Faheem Mitha Mar 28 '11 at 9:36
    
Please share your answer. (meta.stackoverflow.com/questions/12513/…) –  dogbane Mar 28 '11 at 9:48
add comment

1 Answer

up vote 1 down vote accepted

The commands below will work for percentages above 50% (if you want to split only into two files), quick and dirty approach.

1) split 70% based on lines

split -l $[ $(wc -l filename|cut -d" " -f1) * 70 / 100 ] filename 

2) split 70% based on bytes

split -b $[ $(wc -c filename|cut -d" " -f1) * 70 / 100 ] filename
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.