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

appending with AWK

Status
Not open for further replies.

harris2107

IS-IT--Management
Aug 18, 2007
3
US
Hi all,
I have two files called INPUT1 and INPUT2 and i am trying to append the values of INPUT1 to INPUT2 using AWK.

The INPUT1 file will always has a single field and the INPUT2 file has 3 fields but both files will have same number of records always. Following is the format of the two files,

INPUT1:

PROD
DEV
QA

INPUT2:

DB1,PRIMARY,NY
DB2,SECONDARY,CA
DB3,TERTIARY,MN

Now, the issue i am working on is to append the values of INPUT1 to the file INPUT2 using awk. So, after appending the output should look like following,

DB1,PRIMARY,NY,PROD
DB2,SECONDARY,CA,DEV
DB3,TERTIARY,MN,QA

i.e., the first record of INPUT1 should be appended to the 1st record (last field) of INPUT2 and so on...... As i said the number of records in each file will be same. So, each record in file1 should be appended to corresponding record in file2.

Any suggestions?

Thanks,
Harris.
 
What about this ?
awk 'FNR==NR{a[NR]=$1;next}{print $0","a[FNR]}' INPUT1 INPUT2

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
harris2107,
pls do not post to multiple forums

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad, just to know:
why do you think it's bad to ask in different places ?
 
It's not that it's "bad". Actually on many occasions I've referred people to other forums myself to get a more detailed information and/or information from the more knowldgeable audience.

But... at the same time I've seen people posting to multiple forums ALL at the time just to get the quickest solution. In most cases of the latter, those folks never showed any hint of the curiosity in the posted solution and simply vanish till the 'fire' starts burning.

So (at last based on my observations) when I see the pattern of the 'multiple forum postings' to me it's a somewhat clear indication of the "leaching phenomenon' which I've been trying to keep the forums I've been posting to clear off.

Once again - this is my personal observation and 'your mileage may vary'.


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I know this is an AWK forum, but this also works:

paste -d, INPUT2 INPUT1


HTH,

p5wizard
 
Hi,
Thank you all for the replies.

vgersh99 - Yes you are correct but as you have said, the only reason for me posting in different forums is to get the quickest solution possible. Sorry, but this is how the newbies get to survive.
 
Let's say that a person posts the same problem in forums A, B, C, and D without telling that he has posted in more than one forum. He receives a reply in forum D that satisfies him and reports this in forum D but doesn't tell forums A, B, and C. (And of course he doesn't bother to click the magic link.) Subsequently, on each of the 3 remaining forums, two programmers create and post solutions---a total of 6 programs that are never used and never even read by the o.p., who doesn't care how much of other people's time he wastes.

Anyone who uses newsgroups knows that it's wrong to post a problem in more than one group simultaneously.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top