Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify a file with data store in an other file.

Status
Not open for further replies.

EboneSup

IS-IT--Management
Feb 25, 2002
11
0
0
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
 

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 ----------------
 
Thanks vgersh99,

it's working if you use &quot;gsub(i, arr);&quot;

JM
 
Ok
it seems that
Code:
[i]
was not displaied !
good line is
Code:
gsub(i,arr[i])
;
 
darn TGML chopping off mah arrays - sorry about that

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top