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

AWK solution (ordered by sort command):

awk 'NR==FNR{ a[$1]; next }$1 in a' file1 FS='[[:space:]]*,[[:space:]]' file2 | sort 
  • FS='[[:space:]]*,[[:space:]]' - field separator specifiedthat is set for file2

The output:

aa , 6 , tg16 bb , 7 , tg17 cc , 8 , tg18 dd , 3 , tg13 

AWK solution (ordered by sort command):

awk 'NR==FNR{ a[$1]; next }$1 in a' file1 FS='[[:space:]]*,[[:space:]]' file2 | sort 
  • FS='[[:space:]]*,[[:space:]]' - field separator specified for file2

The output:

aa , 6 , tg16 bb , 7 , tg17 cc , 8 , tg18 dd , 3 , tg13 

AWK solution (ordered by sort command):

awk 'NR==FNR{ a[$1]; next }$1 in a' file1 FS='[[:space:]]*,[[:space:]]' file2 | sort 
  • FS='[[:space:]]*,[[:space:]]' - field separator that is set for file2

The output:

aa , 6 , tg16 bb , 7 , tg17 cc , 8 , tg18 dd , 3 , tg13 
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

AWK solution (ordered by sort command):

awk 'NR==FNR{ a[$1]; next }$1 in a' file1 FS='[[:space:]]*,[[:space:]]' file2 | sort 
  • FS='[[:space:]]*,[[:space:]]' - field separator specified for file2

The output:

aa , 6 , tg16 bb , 7 , tg17 cc , 8 , tg18 dd , 3 , tg13