Vlookup on 2 files - inserting vlookup command on another command

Hello, i am trying to print group name column(etc/group) on script (etc/passwd) since group name is not listed on etc/passwd columns. Im trying to do a vlookup. but i cant figure out how i can insert the vlookup command FNR==NR inside the print out command or the output. I also tried exporting etc/group and etc/passwd on a file but still cant find a way on how to do it.

awk -F":" -v TNR=$(wc -l < passwd.sh) '
BEGIN { NUM_PAGES=TNR/10+1
        print "--------------------------------------------------"
        printf "%-20s %-10s %-3s\n","USERNAME","GUID","DIRECTORY"
        print "--------------------------------------------------" }

!(NR%10) { PAGE++
           printf "--- Page %d of %d ---",PAGE,NUM_PAGES
           getline rc < "-"; system("tput cuu1") }

 #(NR==FNR) {a[$4];next}$3 in a{print $3}
 { printf "%-20s %-10s %-30s\n", $1,$3, $7 } ' group.sh  passwd.sh

Do you mean something like this?

awk -F: '
  NR==FNR {
    A[$3]=$1
    next
  }

  $4 in A {
    $4=A[$4]
  }

  {
    printf "%-20s %-10s %-30s\n", $1,$4,$7 
  }
' /etc/group /etc/passwd
2 Likes

absolutely yes! thank you so much!