![]() |
|
|
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 |
| Split large file and add header and footer to each small files | ashish4422 | Shell Programming and Scripting | 7 | 07-07-2008 03:13 PM |
| Split large file and add header and footer to each file | ashish4422 | Shell Programming and Scripting | 1 | 04-15-2008 07:12 AM |
| Need to split a large data file using a Unix script | SAIK | HP-UX | 1 | 03-29-2006 05:05 PM |
| Split A Large File | nbvcxzdz | Shell Programming and Scripting | 4 | 11-14-2005 08:48 AM |
| prevent file size is too large | ust | UNIX for Dummies Questions & Answers | 2 | 03-10-2005 02:04 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
I have a large file with a repeating pattern in it. Now i want the file split into the block of patterns with a specified no. of lines in each file. i.e. The file is like 1... 2... 2... 3... 1... 2... 3... 1... 2... 2... 2... 2... 2... 3... where 1 is the start of the block and 3 is the end of the block. Now i want the file to be split up in blocks. But each file can have more than one block, but specified no. of lines or less. What i have done is i split up the file using Code:
awk '/^1/{close("file"f);f++}{print $0 > "file"f}' testfile
Please give me an efficient way to do this. I feel we can do it in the awk command only. Thanks, CSS Last edited by Yogesh Sawant; 06-24-2008 at 04:36 AM.. Reason: added code tags |
|
||||
|
Quote:
|
|
||||
|
Quote:
But i had to make some minor changes and this worked. awk '/^1/{f=1} f{ print $0 > "file_"n ; c++} c>10000 && /^3/ { n++; c=1; close("file_"n) }' c=1 n=1 testfile |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|