![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Append to end of each line of file without a temp file. | rorey_breaker | Shell Programming and Scripting | 4 | 04-03-2008 07:11 AM |
| How to Append a Value to each line of the file | dsshishya | UNIX for Dummies Questions & Answers | 11 | 03-21-2008 10:48 AM |
| Append line based on fixed position | ashikin_8119 | Shell Programming and Scripting | 2 | 03-19-2008 12:09 AM |
| Append Line From a File To Another File | panknil | Shell Programming and Scripting | 3 | 05-28-2007 10:15 PM |
| append field to file(nawk) | axl | Shell Programming and Scripting | 4 | 11-14-2004 01:19 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Append a field to the end of each line of a file based on searching another file.
Hi All,
I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, 1002,JHS,26,F, 1003,JOS,42,M, ................... FileB EmpNo,Spouse, 1000,DEB, 1002,FAR, ................ FileA has say 20000 lines and FileB has 1000. What I am trying to do is to append the spouse's name in the FileA if the employee is married. Else I need to append a N.A., or something. So for each EmpNo in FileA, I need to check FileB for a matching first column, and if a match is found append FileA with second column of FileB. Else Append a N.A. to the end of that line. So my output file should be something like the one shown below. FileC EmpNo,Name,Age,Sex,Spouse, 1000,ABC,23,M,DEB, 1001,DES,24,F,N.A., 1002,JHS,26,F,FAR, 1003,JOS,42,M,N.A., I know this can be done using awk or sed. But I am not much familier with them either. Please help me with some pointers to tackle this.. Some sample codes are most welcome.. Thanks in Advance. Ultimate. Last edited by ultimate; 03-29-2005 at 03:58 AM. Reason: Subject modification |
| Forum Sponsor | ||
|
|
|
|||
|
Thanks a lot vgersh99!!
This exactly satisfies the need.. Now i realize that i know nothing about awk.. I have been trying for half a day to accomplish this.. Great help.. Btw, I did not have nawk, and tried with awk and it works fine.. Is there any big difference b/w both? Last edited by ultimate; 03-29-2005 at 10:49 AM. |
|||
| Google UNIX.COM |