The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Please Help:Need to Split the file into mutliple files depends on the KEY field value arund_01 UNIX for Dummies Questions & Answers 14 04-23-2008 03:42 PM
Split file into multiple files depending upon first 4 digits deepakgang Shell Programming and Scripting 4 04-09-2008 01:21 AM
Help Needed : Split one big file to multiple files monicasgupta Shell Programming and Scripting 5 03-03-2008 07:09 PM
Split A File Into 2 Files dummy_needhelp Shell Programming and Scripting 7 11-04-2007 07:36 PM
Split File into seperate files eltinator Shell Programming and Scripting 4 08-03-2007 02:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-16-2006
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Unhappy Split a file into 2 or more files

Dear friends:

I have a datafile contains 1 to 40 lines or i can be varied between 1 to 40. I want to split the datafile into smaller files:

if the datafile has 40 lines or more,

file1 contains line 1 to 12
file2 contains line 13 to 25
file3 contains line 26 to 28
file4 contains line 29 to 40 (increment of 12)

and if the datafile has 12 lines or less
do nothing

Please advise

I got the idea of wc datafile

if datafile > 12 lines
save line1 to 12 > file1
save line13 to 25 > file ....
if datafile <= 12 lines
do nothing

I am lack of experience of unix syntax..

Many thanks!
  #2 (permalink)  
Old 01-16-2006
sssow sssow is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 179
You can use sed for this

if [ $(wc -l datafile|awk '{print $1}') -gt 12 ]
then
sed -n '1,12p' datafile >file1
else
echo less than 12 lines
fi

Last edited by sssow; 01-16-2006 at 12:48 PM..
  #3 (permalink)  
Old 01-16-2006
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Thank you! I will try it ASAP
  #4 (permalink)  
Old 01-16-2006
ppierald ppierald is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 11
You can also try the 'split' command.
  #5 (permalink)  
Old 01-16-2006
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
I tried SPLIT comand it worked great. I was able to choose lines number or number characters.

Thank you very much all the friends to take the time to helps!
Sponsored Links
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 08:58 PM.


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