Skip to main content
added 1 character in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

Here is another awk solution, similar to @Thor's answer, less concise but more efficient:

awk '!NF {print;next}; !($0 in a) {a[$0];print}' file

With this, we only check a[$0] has existed or not. If not, initializing it then print. In this case, we don't have any reference, assignment to a[$0] if it existed.

Here is another awk solution, similar to @Thor's answer, less concise but more efficient:

awk '!NF {print;next} !($0 in a) {a[$0];print}' file

With this, we only check a[$0] has existed or not. If not, initializing it then print. In this case, we don't have any reference, assignment to a[$0] if it existed.

Here is another awk solution, similar to @Thor's answer, less concise but more efficient:

awk '!NF {print;next}; !($0 in a) {a[$0];print}' file

With this, we only check a[$0] has existed or not. If not, initializing it then print. In this case, we don't have any reference, assignment to a[$0] if it existed.

Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

Here is another awk solution, similar to @Thor's answer, less concise but more efficient:

awk '!NF {print;next} !($0 in a) {a[$0];print}' file

With this, we only check a[$0] has existed or not. If not, initializing it then print. In this case, we don't have any reference, assignment to a[$0] if it existed.