Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:20:22+00:00 2026-06-04T23:20:22+00:00

I learned a really handy way to remove duplicate lines retaining the order from

  • 0

I learned a really handy way to remove duplicate lines retaining the order from Remove duplicates without sorting file – BASH.

Say, if you have the following file,

$cat file
a
a
b
b
a
c

you can use the following to remove the duplicate lines:

$awk '!x[$1]++' file
a
b
c

How does this work in terms of precedence of operations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:20:24+00:00Added an answer on June 4, 2026 at 11:20 pm

    The expression is parsed as

    !(x[$(1)]++)
    

    So, from the inside out, it’s:

    • Take field 1 of the current input line, $(1) (note that $ is an operator in AWK, unlike in Perl).
    • Index x with the value of field 1; if x is an unbound variable, bind it to a new associative array.
    • Post-increment x[$(1)]; a rule similar to the one in C applies, so the value of the expression is that of x[$(1)] prior to the increment, which will be zero if x[$(1)] has not yet been assigned a value.
    • Negate the value of the previous, which will yield truth when x[$(1)] is zero.
    • Actually do the increment so that x[$(1)] gets a non-zero value. So, the next time, x[$(1)] for the same value of $(1) will return 1.

    This expression is then evaluated for every line in the input and determines whether the implied default action of awk should be executed, which is to echo the line to stdout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I think i might have learned something (not sure), i'm not really a
I learned of gist.github.com from Mozilla Ubiquity , and have been using it to
I learned something about DLL's yesterday. But I haven't found the way how to
I program using PhoneGap and learned that cross-platform apps really produces slow applications compared
I've learned enough to begin writing programs from scratch, but I'm running into the
I just learned about list comprehension, which is a great fast way to get
Well, I'm learning C++ and never really learned how to do stuff that is
I have learned that the best way to learn a language is by finding
I learned from this article that to avoid confliction between javascript libraries, use jQuery.noConflict();
I learned from the websitethat I should add the code declaration in python when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.