![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Awking!! Printing decimal output is struck | divzz | Shell Programming and Scripting | 4 | 05-28-2008 08:02 AM |
| Splitting huge XML Files into fixsized wellformed parts | Malapha | Shell Programming and Scripting | 0 | 03-17-2008 11:35 AM |
| grepping many values from same files | Sreejith_VK | Shell Programming and Scripting | 2 | 03-15-2008 08:41 AM |
| grepping lines out of files | mariner | UNIX for Advanced & Expert Users | 2 | 09-24-2004 08:12 AM |
| diff 2 files; output diff's to 3rd file | blt123 | Shell Programming and Scripting | 2 | 05-28-2002 11:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
awking and grepping parts of files: the 'super diff'
OKAY----
Here's what I must do. I have two files. I need to compare the two files such as with the diff command. I am adding FILENEW to FILEOLD If fields $1, $2, $5, and 6 are the same, then I don't want to add FILENEW records to FILEOLD. If they are not, then append the lines. Is this possible in the UNIX scripting world? It seems that this could be done in AIX. I also have Perl as a last resort. Looking hard, wondered if anyone has done something like this before. ![]() |
|
||||
|
Does anybody want to take a crack at this?
My slow brain is simply not understanding. If for example: awk 'BEGIN{FS=OFS=","} NR==FNR{a[$1]=$0; next} a[$1]{$0=$0 RS a[$1]}{print}' file2 file1 Adds a line to file1 if the first field matches in both files. How do you only print the line if say, fields1, 2, 5, and 6 match both files? And of course, I would have to reverse that (i.e., only add the lines to file1 if fields 1, 2, 5, and 6 are NOT matched between file1 and file2) Obviously the first FNR line is file2, a[$1] being the first field. The second line then matches a[$1] and appends a record to the output of file1. ![]() Thanks much for any assistance. |
|
||||
|
File1:
---------------------------- apples,pears,bananas,oranges,grapefruit,watermelon,pineapple epples,pears,bananas,oranges,grapefruit,watermelon,pineapple epples,paars,bananas,oranges,grapefruit,watermelon,pineapple graby,epples,bananas,oranges,grapefruit,watermelon,pineapple File2: ---------------------------- pearsrs,apples,bananers,orangas,grapefruit,graby,pineapples apples,pears,bandanas,orangatangs,grapefruit,watermelon,wineapple Wanted output: (File1: appended: only add records when fields 1, 2, 5 and 6 DO NOT match) ----------------------------- apples,pears,bananas,oranges,grapefruit,watermelon,pineapple epples,pears,bananas,oranges,grapefruit,watermelon,pineapple epples,paars,bananas,oranges,grapefruit,watermelon,pineapple graby,epples,bananas,oranges,grapefruit,watermelon,pineapple pearsrs,apples,bananers,orangas,grapefruit,graby,pineapples |
|
||||
|
Basically what this is is a logfile that has alerts from a program.
The entries get dropped into a file continually. But some entries have the same date, transaction ID, location, alert code and keep getting dropped in over and over (like until the problem is fixed) The awk filter is to create a 2nd file that just adds new messages if they are not the same date, ID, location, code, and run on a continual basis filtering these out. |
|
||||
|
Thanks
But something is awry. OKAY, If I do: nawk -f jeffawk file2 file1 ------------------------ apples,pears,bananas,oranges,grapefruit,watermelon,pineapple epples,pears,bananas,oranges,grapefruit,watermelon,pineapple epples,paars,bananas,oranges,grapefruit,watermelon,pineapple graby,epples,bananas,oranges,grapefruit,watermelon,pineapple This is basically a cat of file1. If I do: nawk -f jeffawk file1 file2 I get the following: ----------------------- pearsrs,apples,bananers,orangas,grapefruit,graby,pineapples apples,pears,bananas,oranges,grapefruit,watermelon,pineapple The first line, 'pearsrs', is right on the money. But this is basically a cat of file2. Not sure ? ? ? ? Last edited by jeffpas; 07-17-2008 at 04:19 PM.. |
| Sponsored Links | ||
|
|