![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 file | ashish4422 | Shell Programming and Scripting | 1 | 04-15-2008 06:12 AM |
| rowcnt except Header & Footer | vsubbu1000 | Shell Programming and Scripting | 3 | 08-03-2007 04:50 AM |
| Total of lines w/out header and footer incude for a file | gzs553 | Shell Programming and Scripting | 1 | 11-16-2006 07:42 PM |
| Need to Chop Header and Footer record from input file | coolbudy | Shell Programming and Scripting | 4 | 08-09-2005 12:26 PM |
| Splitting large file into small files | dncs | Shell Programming and Scripting | 4 | 06-08-2005 11:02 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Split large file and add header and footer to each small files
I have one large file, after every 200 line i have to split the file and the add header and footer to each small file?
It is possible to add different header and footer to each file? |
|
||||
|
Content of large file:-
E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538 E109,0,06-mar-07,0,E001,E001,A,78000,6500,37.5 E110,0,09-dec-2008,0,E001,E001,A,56000,4666.667,26.923077 E104,0,06/04/1994,0,E001,E003,A,95000,7916.667,45.673077 E105,0,7/30/1993,0,E001,E003,A,87000,7250,41.826923 E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E108,0,01-feb-2008,0,E001,E003,A,15000,1250,7.211538 E109,0,2/15/1995,0,E001,E001,A,78000,6500,37.5 small file contain:- file1.txt E001 start E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538 E001 End file2.txt E002 Start E109,0,06-mar-07,0,E001,E001,A,78000,6500,37.5 E110,0,09-dec-2008,0,E001,E001,A,56000,4666.667,26.923077 E002 End |
|
||||
|
Perhaps you can adapt something like this to do what you want:
Code:
$ split -d -l 3 temp.txt file && for X in file*; do { echo "$X start"; cat $X; echo "$X end"; } > $X.txt; done
Splits the file every three lines, naming each split-off file with "file" followed by digits. The for loop then takes each file, writes the "start" section, the contents of the file, then the "end" section, and names it with the same file name but with a ".txt" at the end. Working example: Code:
$ cat temp.txt
E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769
E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538
E109,0,06-mar-07,0,E001,E001,A,78000,6500,37.5
E110,0,09-dec-2008,0,E001,E001,A,56000,4666.667,26.923077
E104,0,06/04/1994,0,E001,E003,A,95000,7916.667,45.673077
E105,0,7/30/1993,0,E001,E003,A,87000,7250,41.826923
E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769
E108,0,01-feb-2008,0,E001,E003,A,15000,1250,7.211538
E109,0,2/15/1995,0,E001,E001,A,78000,6500,37.5
$ split -d -l 3 temp.txt file && for X in file*; do { echo "$X start"; cat $X; echo "$X end"; } > $X.txt; done
$ cat file00.txt
file00 start
E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769
E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538
E109,0,06-mar-07,0,E001,E001,A,78000,6500,37.5
file00 end
$ cat file01.txt
file01 start
E110,0,09-dec-2008,0,E001,E001,A,56000,4666.667,26.923077
E104,0,06/04/1994,0,E001,E003,A,95000,7916.667,45.673077
E105,0,7/30/1993,0,E001,E003,A,87000,7250,41.826923
file01 end
$ cat file02.txt
file02 start
E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769
E108,0,01-feb-2008,0,E001,E003,A,15000,1250,7.211538
E109,0,2/15/1995,0,E001,E001,A,78000,6500,37.5
file02 end
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|