Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
bash-3.00# cat > b1.txt
bash-3.00# cat > b2.txt
bash-3.00# awk -F"[,|]" 'NR==FNR{a[$1]++;next} !a[$2]' b1.txt b2.txt

When NR==FNR returns true for first file a[$1] gets incremented. next brings back to beginning of the script. But what is !a[$2] doing here? How does it print without even a print command?

share|improve this question
I'd advise not running / testing scripts as root unnecessarily. Use a normal user account until you are sure the script is safe enough for root. – jw013 Nov 27 '12 at 17:06
up vote 3 down vote accepted

From the POSIX awk spec:

An awk program is composed of pairs of the form:

pattern { action }

Either the pattern or the action (including the enclosing brace characters) can be omitted. ... [A] missing action shall be equivalent to:

{ print }

In your case, !a[$2] is the pattern, and the action is missing.

share|improve this answer
hi @jw013,can you add a bit more,, i mean i dont understand how !a[$2] is working to give the output..Thanks – munish Nov 27 '12 at 17:06
@munish Then put that in your question. What part of it don't you understand? If you don't understand basic awk, you should go read an awk tutorial. This site is for asking specific questions. – jw013 Nov 27 '12 at 17:08
i got it thanks – munish Nov 27 '12 at 17:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.