The UNIX and Linux Forums  


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
File Splitting dncs Shell Programming and Scripting 5 12-06-2007 07:47 AM
file splitting dhams Shell Programming and Scripting 8 08-23-2007 07:12 PM
[Splitting file] Extracting group of segments from one file to others ozgurgul Shell Programming and Scripting 1 09-14-2006 01:17 PM
File splitting praveen.pinto UNIX for Dummies Questions & Answers 9 02-10-2005 04:32 PM
file splitting praveen.pinto UNIX for Advanced & Expert Users 2 02-10-2005 09:54 AM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-22-2008
Vaddadi Vaddadi is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 8
Need help in splitting the file

Hi,

I got a file which may have 100 - 500 rows with header and trailer... based on the total number of real rows ( excluding header and trailer) I want to break the file in 3 or 4 files ..

Coded like this .. but giving error in the AWK in 8th line of below code.

Code:
awk 'NR > 5 {print line} {line = $0}' run.out > run2.out
tfile_length=`wc -l run2.out | cut -c1-8`	       	
tfile_len1=`expr $tfile_length - 3`
echo ' total rows in file  --------------' $tfile_len1
one_third=`echo "scale=0; $tfile_len1 / 3" | bc`
echo ' One third rows in file  --------------' $one_third
head -$one_third run2.out	 > $TEMPDIR/run1_3.out
awk 'NR > $one_third {print line} {line = $0}' run2.out > run3.out
head -$one_third $TEMPDIR/run3.out	> run2_3.out
two_third=`expr $one_third + $one_third`
echo ' Two third rows in file  --------------' $two_third
awk 'NR > $two_third {print line} {line = $0}' run2.out > run3_3.out


Is there any simple way to split to file in 3 or 4 parts based on total rows it has.

Thanks .. Shyam ..

Last edited by Yogesh Sawant; 05-22-2008 at 12:46 PM.. Reason: added code tags
 

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 05:52 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