Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-21-2009, 01:34 PM   #1
LQ Newbie
Registered: May 2008
Posts: 27

Rep: Reputation: 0
spliting a text file into several parts by line count

I have a utility that works with files. The utility is crashing at after about 120 files. The input to the utility is a file containing a filelist. I want to cut the file with the file names in it to seperate files containing about one hundred or so.

My thought was to determine the number of lines/100 and then use head and delete to create temporary files to run the utility multiple times to prevent the crash.

When I tried to create a variable using the wc -l command the output gives me the number of total lines but it also includes the filename of the input file. ( 873 Filename.txt ) I can not figure out how to remove the Filename.txt from the variable.

Any suggestions to any or all of this would be greatly appreciated.

Old 09-21-2009, 01:37 PM   #2
Senior Member
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
man split, specifically:
split -l 100 input_file
Check the man page for options on getting more sensible output filenames.
Old 09-21-2009, 01:49 PM   #3
LQ Newbie
Registered: May 2008
Posts: 27

Original Poster
Rep: Reputation: 0
I was not aware of the split command



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
bash: how to split a text file in two unequal parts Humbro Programming 7 11-23-2007 07:15 AM
Count occurances of a string in a text file MicahCarrick Linux - Software 1 06-24-2006 04:25 PM
Copying parts of a text file austen77 Linux - Newbie 3 09-01-2005 09:56 PM
Count number of line in a file. philipina Programming 7 03-18-2004 05:04 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:30 AM.

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