Compare different column values together between two files and if match print different column value
-1
votes
1
answer
234
views
File1 has data as below , is the field separator
1,T_EXIT,9053.0,10325.0,, ,
2,V_TURN,120.0,11334.0,,GOAL,RECK
3,Q_ENTRY,122.0,190.0,, ,
4,Q_ENTRY_RUN,130.0,569.0,, ,
File2 has data
SYNC CLK
T_EXIT OPEN
Q_ENTRY CLOSE ALLOW
CORE_T MODE
I want to compare column1 of file2 with column2 of file1 and if EXCAT MATCH is there I want to copy column2 from file2 in column6 and column3 from file2 in column7 in file1
I want output as:
1,T_EXIT,9053.0,10325.0,,OPEN,
2,V_TURN,120.0,11334.0,,GOAL,RECK
3,Q_ENTRY,122.0,190.0,,CLOSE,ALLOW
4,Q_ENTRY_RUN,130.0,569.0,, ,
I tried below code, but I could not get how to save two column values column1 and column2 together from file2.
awk 'NR==FNR{A[$1]=$2;B[$1]=$3;next} ($1 in A) {$6=A[$1]; $7=B[$1]}1' file2 FS=, OFS=, file1 > test
Asked by Shreya
(139 rep)
Mar 16, 2023, 03:22 PM
Last activity: Mar 17, 2023, 01:25 PM
Last activity: Mar 17, 2023, 01:25 PM