![]() |
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 |
| how do i pattern match a field with awk? | someone123 | Shell Programming and Scripting | 4 | 06-03-2008 08:08 AM |
| match field between 2 files | phamp008 | Shell Programming and Scripting | 8 | 01-23-2008 07:46 AM |
| regexp to print after a field seperator | ramky79 | Shell Programming and Scripting | 7 | 05-09-2007 06:31 PM |
| egrep field print | knc9233 | UNIX for Dummies Questions & Answers | 2 | 02-14-2007 02:07 PM |
| match a pattern, print it and the next line | nymus7 | Shell Programming and Scripting | 4 | 07-29-2005 12:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Print last occurrence if first field match
Hi All,
I have an input below. If the term in the 1st column is equal, print the last row which 1st column is equal.In the below example, it's " 0001 k= 27 " and " 0004 k= 6 " (depicted in bold). Those terms in 1st column which are not repetitive are to be printed as well. Can any body help me by using awk or perl ? Thanks Input: 0001 k= 1 0001 k= 26 0001 k= 27 0002 k= 1 0003 k= 1 0004 k= 1 0004 k= 4 0004 k= 5 0004 k= 6 Output: 0001 k= 27 0002 k= 1 0003 k= 1 0004 k= 6 |
|
||||
|
Quote:
That's cool!! It works!! You a are brillant!! But i ' m new to the " prev " and " FNR " term. Can you explain your code so that i can understand better ? |
|
||||
|
Hi vgersh99,
If i need to capture the 1st occurrence instead that is if column1 of row1 equals to column1 of row2 then the whole line of column1 row1 is being printed out , how can i modify your code below to fulfill this requirement? Code:
$1 != prevIDX && FNR != 1 { print prev}
{ prevIDX=$1; prev=$0 }
END { print prev }
0001 k= 1 0001 k= 26 0001 k= 27 0002 k= 1 0003 k= 1 0004 k= 1 0004 k= 4 0004 k= 5 0004 k= 6 Output: 0001 k= 1 0002 k= 1 0003 k= 1 0004 k= 1 Last edited by Raynon; 03-13-2008 at 07:07 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|