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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split large file and add header and footer to each small files ashish4422 Shell Programming and Scripting 7 07-07-2008 02:13 PM
Split large file and add header and footer to each file ashish4422 Shell Programming and Scripting 1 04-15-2008 06:12 AM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
Strange difference in file size when copying LARGE file.. 0ktalmagik Filesystems, Disks and Memory 1 06-03-2006 07:34 PM
Need to split a large data file using a Unix script SAIK HP-UX 1 03-29-2006 04:05 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 11-14-2005
nbvcxzdz nbvcxzdz is offline
Registered User
  
 

Join Date: Dec 2003
Posts: 17
Split A Large File

Hi,

I have a large file(csv format) that I need to split into 2 files. The file looks something like

Original_file.txt
first name, family name, address
a, b, c,
d, e, f,
and so on for over 100,00 lines

I need to create two files from this one file. The condition is i need to ensure both files have the header row "first name, family name, address" AND the second file only starts from the 60,000th row of original_file.txt

Can some please show me the code to do this in a shell script?

Really Appreciated

Thanks
  #2 (permalink)  
Old 11-14-2005
futurelet futurelet is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 137
Awk:

Code:
1==NR || 60000==NR {
  whichfile++
  output( "first name, family name, address" )
}
{ output( $0 ) }

function output( s )
{ print s  >( "output" whichfile ".csv" )
}
  #3 (permalink)  
Old 11-14-2005
sergilda sergilda is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 1
Hi,

you can make the first file by using:

head -60000 filename > filename_1to60000

you can make the second one as follow:

echo 'first name, family name, address' > filename_60001to100000
tail +60001 filename >> filename_60001to100000

Kind regards
  #4 (permalink)  
Old 11-14-2005
nbvcxzdz nbvcxzdz is offline
Registered User
  
 

Join Date: Dec 2003
Posts: 17
I will try it out...thanks ill let you know how it goes
  #5 (permalink)  
Old 11-14-2005
jerardfjay jerardfjay is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 146
use the split command

split -l 60000 in_file

In case of more complex fragmentation of a file, use the context based split command csplit.

Jerardjay
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 03:39 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