LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-19-2016, 04:14 PM   #1
CaptainDerp
LQ Newbie
 
Registered: Mar 2013
Posts: 27

Rep: Reputation: Disabled
How to split a file using 'split ' without destroying lines?


Im using split to break up a text file into 20 equal chunks.

Code:
split -N 20 somefile.txt
Ok thats fine, but the problem is, split will at some point cut the ending line in half and dump its chopped contents to the next file, meaning, if the last line in a chunk is 'something' well, 'some' might end up being the last line of the new chunk, and 'thing' will be the first line of the next chunk created.

I want split to knock this BS off and stop corrupting my data, and/or somehow preserve each line in one piece.

Does anybody have any constructive ideas how to remedy this problem?
 
Old 09-19-2016, 04:27 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Code:
split -nl/20 somefile.txt
 
2 members found this post helpful.
Old 09-19-2016, 08:09 PM   #3
CaptainDerp
LQ Newbie
 
Registered: Mar 2013
Posts: 27

Original Poster
Rep: Reputation: Disabled
You are Fired.

Sir, you are fired. that nonsense does not work.

Code:
# split -nl/24 file.txt
split: invalid option -- 'n'
Try `split --help' for more information.
 
Old 09-19-2016, 08:13 PM   #4
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
Your split is fired, my split has -n option.
 
Old 09-19-2016, 08:17 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 633

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
Originally Posted by CaptainDerp View Post
Sir, you are fired. that nonsense does not work.

Code:
# split -nl/24 file.txt
split: invalid option -- 'n'
Try `split --help' for more information.
This is correct and works as expected.
I'd help more, but your rude behavior isn't appreciated. Good luck "firing" me.
 
Old 09-19-2016, 08:19 PM   #6
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,398
Blog Entries: 8

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
split -nl/20 somefile.txt

It works for me on Debian 8.
 
1 members found this post helpful.
Old 09-20-2016, 04:08 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
I use split from GNU coreutils, don't know for other version

https://www.gnu.org/software/coreuti...nvocation.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
split file into chunks delimited by blank lines elalexluna83 Programming 8 06-25-2015 05:35 AM
[SOLVED] Split a file into two - the first being the first two lines and the second the rest jasonws Linux - General 2 11-02-2010 04:32 AM
Scripting: split file into 12 lines array zklone Programming 12 12-07-2009 10:02 PM
split very large 200mb text file by every N lines (sed/awk fails) doug23 Programming 8 08-10-2009 06:08 PM
How to split file , .. awk or split ERBRMN Linux - General 9 08-15-2006 12:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration