http://www.unixcl.com/2008/03/remove-duplicates-without-sorting-file.html …https://stackoverflow.com/a/11532197/494061 …
-
-
-
Oooh, very nice!
ಸಂವಾದದ ಮುಕ್ತಾಯ
ಹೊಸ ಸಂವಾದ -
-
-
uniq (1)
-
Requires a pre-sorted file
ಸಂವಾದದ ಮುಕ್ತಾಯ
ಹೊಸ ಸಂವಾದ -
-
-
Don't you like "uniq"?
-
I do but `uniq` needs sorted input.
-
You are right it seems I never had the unsorted requirement so far. Good job then ;-)
-
One other way the awk method is useful is you don't need to compare the whole line. For instance, in a web server log you may only care to see when it's an new unseen remote client, so use $1 instead of $0.
-
In more complicated production cases I would prefer to write a small go(lang) tool and just code in (less dense) what it should do. I totally love awk, sed and such but if it comes to maintainability it easily gets tough to read and adopt.
#golang
ಸಂವಾದದ ಮುಕ್ತಾಯ
ಹೊಸ ಸಂವಾದ -
-
-
Efficient in what sense? Doesn't this store 'seen' in memory? `sort` uses local disk space as necessary. I use `awk '! seen[$0]++' <( cat /dev/urandom | strings | head -n 1000000000 ) > /dev/null` and I quickly saturate memory. What am I missing?
-
Less memory efficient, but better asymptotic runtime if not memory bound. But my use case was indeed not due to preformance but requiring to preserve the original order.
-
Oh yeah I am _totally_ using this script from now on. Preserving original order is much more comprehensible in many contexts. I was just bristling at shoving every unique line in a hash (unbounded memory growth).
- 1ಮತ್ತಷ್ಟು ಪ್ರತಿಕ್ರಿಯೆ
ಹೊಸ ಸಂವಾದ -
-
-
How did it save your day? Did you specifically need unsorted output? Was there some resource consumption trade-off that worked in your favor? Is your sort implementation wildly inefficient? Inquiring minds want to know.
-
Yes, the original order of the lines matters in my case.
-
Okay, thanks. That makes sense.
ಸಂವಾದದ ಮುಕ್ತಾಯ
ಹೊಸ ಸಂವಾದ -
-
-
Coolio! If I did $1 instead of $0 would it return unique values from column 1? Im Still an AWK white belt :)
-
It would print the whole line (that's the default action), but only the first line for a given, unique value of the first column.
ಸಂವಾದದ ಮುಕ್ತಾಯ
ಹೊಸ ಸಂವಾದ -
-
-
useless use of awk award; man uniq
-
Not at all: `uniq` requires pre-sorted files. I need the original order. The awk solution is also more efficient than `sort | uniq` or `sort -u`.
- 1ಮತ್ತಷ್ಟು ಪ್ರತಿಕ್ರಿಯೆ
ಹೊಸ ಸಂವಾದ -
ಲೋಡಿಂಗ್ ಸಮಯ ಸ್ವಲ್ಪ ತೆಗೆದುಕೊಳ್ಳುತ್ತಿರುವಂತೆನಿಸುತ್ತದೆ.
Twitter ಸಾಮರ್ಥ್ಯ ಮೀರಿರಬಹುದು ಅಥವಾ ಕ್ಷಣಿಕವಾದ ತೊಂದರೆಯನ್ನು ಅನುಭವಿಸುತ್ತಿರಬಹುದು. ಮತ್ತೆ ಪ್ರಯತ್ನಿಸಿ ಅಥವಾ ಹೆಚ್ಚಿನ ಮಾಹಿತಿಗೆ Twitter ಸ್ಥಿತಿಗೆ ಭೇಟಿ ನೀಡಿ.