![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|