Created
January 16, 2011 15:20
-
-
Save cosmin/781874 to your computer and use it in GitHub Desktop.
print only lines with unique fields, keep track of count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #one-liner awk 'NR == 1 {lastfield = $1; matchline = $0; count = 1; next} {if (lastfield != $1) {print count " " matchline; count = 0; matchline=$0; } count += 1; lastfield = $1} END {print count " " matchline}' inp.txt | |
| NR == 1 { | |
| lastfield = $1; | |
| matchline = $0; | |
| count = 1; | |
| next | |
| } | |
| { | |
| if (lastfield != $1) { | |
| print count " " matchline; | |
| count = 0; | |
| matchline=$0; | |
| } | |
| count += 1; | |
| lastfield = $1 | |
| } | |
| END { | |
| print count " " matchline | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment