Feb 25, 2002 #1 EboneSup IS-IT--Management Feb 25, 2002 11 BE Hi guys, I need to modify a file with data store in an other flat file as follow : File1 : X1 must be modified as X2 also X3 and pherhaps X4 File2 : X1 Y4 X2 Y2 X3 Y1 X4 Y3 result file : Y4 must be modified as Y2 also Y1 and pherhaps Y3 Thks JM
Hi guys, I need to modify a file with data store in an other flat file as follow : File1 : X1 must be modified as X2 also X3 and pherhaps X4 File2 : X1 Y4 X2 Y2 X3 Y1 X4 Y3 result file : Y4 must be modified as Y2 also Y1 and pherhaps Y3 Thks JM
Feb 25, 2002 #2 vgersh99 Programmer Jul 27, 2000 2,146 US awk -v file2=modFile.txt2 -f modFile.awk modFile.txt1 --------------- modFile.awk ---------------- BEGIN { while (getline < file2 > 0) { if ( $0 ~ /^[#].*/ ) continue; arr[$1]=$2; } close(file2); } { for (i in arr) gsub(i, arr); print; } --------------- modFile.awk ---------------- Upvote 0 Downvote
awk -v file2=modFile.txt2 -f modFile.awk modFile.txt1 --------------- modFile.awk ---------------- BEGIN { while (getline < file2 > 0) { if ( $0 ~ /^[#].*/ ) continue; arr[$1]=$2; } close(file2); } { for (i in arr) gsub(i, arr); print; } --------------- modFile.awk ----------------
Feb 27, 2002 Thread starter #3 EboneSup IS-IT--Management Feb 25, 2002 11 BE Thanks vgersh99, it's working if you use "gsub(i, arr);" JM Upvote 0 Downvote
Feb 27, 2002 Thread starter #4 EboneSup IS-IT--Management Feb 25, 2002 11 BE Ok it seems that Code: [i] was not displaied ! good line is Code: gsub(i,arr[i]) ; Upvote 0 Downvote
Feb 27, 2002 #5 vgersh99 Programmer Jul 27, 2000 2,146 US darn TGML chopping off mah arrays - sorry about that vlad Upvote 0 Downvote