![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find and FTP multiple files in Korn Shell | lambjam | UNIX for Dummies Questions & Answers | 2 | 08-13-2007 07:50 PM |
| Constantly updating log files (tail -f? grep? awk?) | nortonloaf | UNIX for Dummies Questions & Answers | 0 | 12-03-2006 08:20 PM |
| Lookup between 2 files ( korn shell ) | pavan_test | UNIX for Dummies Questions & Answers | 17 | 01-31-2006 01:07 PM |
| How to process multiple files in Korn Shell | stevefox | Shell Programming and Scripting | 3 | 11-22-2005 03:39 AM |
| korn shell + sftp + list files | alienET | Shell Programming and Scripting | 1 | 03-24-2005 08:12 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Korn shell awk use for updating two files
Hi, I have two text files containing records in following format: file1 format is: name1 age1 nickname1 path1 name2 age2 nickname2 path2 file 1 example is: abcd 13 abcd.13 /home/temp/abcd.13 efgh 15 efgh.15 /home/temp/new/efgh.15 file 2 format is: name1 age1 nickname1 name2 age2 nickname2 file 2 example: abcd 13 abcd.13 efgh 21 efgh.21 file 2 is the current (up-to-date) file, and file 1 is the one that needs to update it's records to match file2. file1 contains records that might not exist in file2, and these records need to stay as-is. however, when updating, as in the above example, record efgh needs to be updated to reflect file2's values, so output should look like this: output file: abcd 13 abcd.13 /home/temp/abcd.13 efgh 21 efgh.21 /home/temp/new/efgh.21 how can i achieve this with korn shell scripting (using awk maybe?) thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
nawk -f al.awk file2 file1
al.awk: Code:
FNR==NR { f2[$1]=$0; next }
$1 in f1 {
n=split(f2[$1], arr, FS)
for(i=2; i<=n; i++)
$i=arr[i]
print
next;
}
1
|
|
#3
|
|||
|
|||
|
Thanks, but i can't use nawk for some reason. I"m running hpux 11.11
|
|
#4
|
||||
|
||||
|
so use either 'awk' or 'gawk'....
|
|
#5
|
|||
|
|||
|
thanks vgersh99...
i'm still having a problem with the script though. It appears to just copy the contents of file1 (the out-of-date file) unaltered. any suggestions as to why? file1 format: (out-of-date) abcd 13 abcd.13 /home/temp/abcd.13 efgh 15 efgh.15 /home/temp/new/efgh.15 file2 format: (up-to-date) abcd 13 abcd.13 efgh 21 efgh.21 output file: (DESIRED) abcd 13 abcd.13 /home/temp/abcd.13 efgh 21 efgh.21 /home/temp/new/efgh.21 output file: (PRODUCED) abcd 13 abcd.13 /home/temp/abcd.13 efgh 15 efgh.15 /home/temp/new/efgh.15 note in the PRODUCED output, the values associated with record "efgh" remained the same as they were in file1 (the out-of-date file) rather than updating according to file2's (the up-to-date file) values. any suggestions on how to fix this issue? thanks a lot |
|||
| Google The UNIX and Linux Forums |