The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl-like split function for bash? eur0dad Shell Programming and Scripting 5 09-05-2008 07:23 PM
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 12:39 PM
awk - split function fusionX Shell Programming and Scripting 7 04-10-2008 03:32 AM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
perl split function new2ss Shell Programming and Scripting 5 06-08-2006 11:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2005
ktsirig ktsirig is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
split function

Hi all!
I am relatively new to UNIX staff, and I have come across a problem:
I have a big directory, which contains 100 smaller ones. Each of the 100 contains a file ending in .txt , so there are 100 files ending in .txt
I want to split each of the 100 files in smaller ones, which will contain 2000 lines each.
I think that 'split' command is what I must use, but I don't know how.
I go something like:

find . -name "*.txt" | .....

Any hints on the missing part? How can I apply the split command in each file, without entering each directory?
Thanx
  #2 (permalink)  
Old 09-28-2005
qfwfq qfwfq is offline
Registered User
  
 

Join Date: Feb 2005
Location: Canada
Posts: 133
Lets say you want to split your files into files of 10 lines each.

Code:
find . -name '*.txt' -exec split -l 10 {} \;
man split for other options.

Last edited by qfwfq; 09-28-2005 at 01:32 PM..
  #3 (permalink)  
Old 09-28-2005
ktsirig ktsirig is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
Hi, thanx very much for your time.
Excuse my foolish question, but what are {} \ in your code?

find . -name '*.txt' -exec split -l 10 {} \;

I understand 'find - name '*.txt' ', I suppose -exec is for the system to execute a command, -l 10 I have found it in man split that are the arguments passed for split, but {} and \ I don't understand.
I tried your code, but it didn't work
I am sure that I am lacking something here, if you could just point it out...
  #4 (permalink)  
Old 09-28-2005
ktsirig ktsirig is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
Sorry, it needed :


find . -name '*.txt' -exec split -l 10 {} {} \;

Thanx again!
  #5 (permalink)  
Old 09-29-2005
qfwfq qfwfq is offline
Registered User
  
 

Join Date: Feb 2005
Location: Canada
Posts: 133
It may depend on your version on UNIX, but under HP-UX

Code:
find . -name '*.txt' -exec split -l 10 {} \;
is working fine!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0