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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Two input files be processed at awk..?

Status
Not open for further replies.

Awkunix

Programmer
Apr 8, 2003
3
US
Hi,

I have situation where 2 data files, File A and File B. I need to read record from File A second column and replace third column of File B in sequence order.

File A File B

1 ab 1 a xx
2 ac 2 a yy
3 ad 3 a zz
4 ae 4 a ww

Expected out put is

File B

1 a ab
2 a ac
3 a ad
4 a ae


Can awk accept 2 input files as arguments ? and allow to change $3 in FileB ?

Any help is highly appreciated.

Thanks in Advance

VK
 
something like that:
nawk -f subst.awk fileB
OR
nawk -v fn="path2fileA" -f subst.awk path2fileB
#------------------ subst.awk
BEGIN {
if (!fn) fn = "fileA"
lineA=0
while((getline < fn) > 0)
arr[++lineA] = $0
}
{
if ( NR in arr) {
split(arr[NR], arrSplit, FS);
$NF=arrSplit[2];
}

print;
}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thank you Vgersh99. Its work fine and your code gave me lot of idea in exploring other options with array. I am novice in awk programming and trying to understand awk’s powerfulness. Thanks again for your help.

VK
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top