![]() |
|
|
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 |
| combining fields in two text fields | shocker | Shell Programming and Scripting | 3 | 01-16-2008 11:27 AM |
| GNU PDF to fill missing gap in functionality | iBot | UNIX and Linux RSS News | 0 | 12-01-2007 11:05 AM |
| fill a NIL into the blank field | happyv | Shell Programming and Scripting | 8 | 03-23-2007 04:49 AM |
| align several fields and fill spaces with zero | DebianJ | Shell Programming and Scripting | 2 | 11-23-2005 07:51 AM |
| Esc key/Auto-fill | mr_manny | SUN Solaris | 3 | 10-30-2005 07:12 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Fill the Key fields : Please help us
Hi ....
we are having the below file .Column 1, Column 2 ,column 3 are key fields... In the below ...for 2 nd , 3 rd row the repeated key column is missing .... i want the new file to be populated with all missing key columns. E100,0,5/29/1993,0,E001,E000,A,500000,41666.667,240.384615 _____0,1/23/1994,0,E001,E003,A,125400,10450,60.288462 _____0,6/4/1994,0,E001,E003,A,95000,7916.667,45.673077 E101,0,7/30/1993,0,E001,E003,A,87000,7250,41.826923 ______ 1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E103,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538 E104,0,2/15/1995,0,E001,E001,A,78000,6500,37.5 I want the result to be : E100,0,5/29/1993,0,E001,E000,A,500000,41666.667,240.384615 E100, 0,1/23/1994,0,E001,E003,A,125400,10450,60.288462 E100, 0,6/4/1994,0,E001,E003,A,95000,7916.667,45.673077 E101,0,7/30/1993,0,E001,E003,A,87000,7250,41.826923 E101,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E103,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538 E104,0,2/15/1995,0,E001,E001,A,78000,6500,37.5 Please help me ........ |
|
||||
|
Write an awk script which remembers the fields from the previous line, and adds as many to the front as are missing to form a full line. Assume the first line indicates how many fields a full line should have. Read up on array handling in the awk documentation.
|
|
||||
|
hi era
Quote:
Thanks your response charan |
|
||||
|
It does pretty much what I suggested, except it hard-codes the number of expected fields to 10. You could count the number of fields on the first line and use that on subsequent lines for a slightly more general approach. It remembers $1 in k[1], $2 in k[2], and $3 in k[3]; and if the line has too few fields, prints what's in k[1], k[2], etc from the previous line as many as is required. This explanation is backwards relative to the script because it prints first, and then remembers for the next line.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|