awk Compare 2 files, print match and print just 2 columns of the second file -


i novice , sure silly question searched , didn't find answer. want select 2 columns of file 2. know how select 1 column =$1 , columns =$0. if want show 2,3, ... column file2 in file3, possible?

awk -v rs='\r\n' 'begin {fs=ofs=";"} fnr==nr {a[$2] = $1; next} {gsub(/_/,"-",$2);$2=toupper($2);print a[$2]?a[$2]:"na",$0,a[$2]?a[$2]:"na"}' $file2 $file1 > file3 

or

awk -v rs='\r\n' 'begin {fs=ofs=";"} fnr==nr {a[$2] = $0; next} {gsub(/_/,"-",$2);$2=toupper($2);print a[$2]?a[$2]:"na",$0,a[$2]?a[$2]:"na"}' $file2 $file1 > file3 

i want $1 , $2 file2, code doesn´t work. obtain 1 column data $1 , $2

awk -v rs='\r\n' 'begin {fs=ofs=";"} fnr==nr {a[$2] = $1$2; next} {gsub(/_/,"-",$2);$2=toupper($2);print a[$2]?a[$2]:"na",$0,a[$2]?a[$2]:"na"}' $file2 $file1 > file3 

any solution??

awk -v rs='\r\n' ' # call awk  , set row separator          begin {                   fs=ofs=";"     # set input , output field separator         }           # here reading first argument file2         fnr==nr {                    # save column2 , column3 separated ofs ;                     # file2 first argument, in array                     # index/key being second field/column file2                      a[$2] = $2 ofs $3;                      # stop processing go next line of file1                    next         }         # here on words reading second argument file1         {               # global substitution                # replace _ hyphen - in field2/column2                gsub(/_/,"-",$2);                # uppercase field2/column2                $2=toupper($2);                # if field2 of current file (file1) exists in array               # created above using file2               # print array value field2 , field3 of file2               # else print "na", , output field separator,                # entire line/record of current file                print ($2 in ? a[$2] : "na"), $0           }' $file2 $file1 > file3 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -