Skip to main content
added 42 characters in body
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

With single fast GNU awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • -F'.' - treat . as field separator
  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)

With single fast GNU awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)

With single fast GNU awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • -F'.' - treat . as field separator
  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)
ARGIND is only in GNU awk
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

With single fast GNU awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)

With single fast awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)

With single fast GNU awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

With single fast awk command:

awk -F'.' \
'{
     if (ARGIND == 1) a[$1];
     else if (ARGIND == 2 && $1 in a) comm[$1];
     else if (ARGIND == 3){
         delete a;
         if ($1 in comm) delete comm[$1]
     }
 }
 END{ for (i in comm) print i }' a.txt b.txt c.txt

The output:

c

  • ARGIND - The index in ARGV(array of command line arguments) of the current file being processed
  • comm - array of common items between first 2 files (a.txt and b.txt)