unix - how to use FILENAME to set different files in awk -
i have 2 files lets say... 1) student records having information id,name , city 2) student marks having id ,totalmarks,percentage
student records (file)
101 | nik | mumbai 102 | zeel | chennai 103 | gurav | delhi
student marks (file)
101 | 80 | 80 102 | 90 | 90 103 | 90 | 90
and want retrieve information in forms student name it's percentage
nik | 80 zeel | 90 gurav | 90
how write using awk command
awk -f'|' -v ofs="|" 'nr==fnr{a[$1]=$2;next}$1 in a{print a[$1],$3}' studentfile markfile didn't test, should work.
output like:
nik|80 zeel|90 .... edit
-f'|' #field separator -v ofs="|" #output field separator 'nr==fnr{a[$1]=$2;next} #nr overall record line number, fnr record line number 1 input file. see man page detail. part processing first input file, , save id , name in array $1 in a{print a[$1],$3}'#now processing 2nd input file, marks. if id in array, print value of array (name), , mark percentage field ($3)
Comments
Post a Comment