Sponsored Content
Top Forums Shell Programming and Scripting How to print Dissimilar keys and their values? Post 302320428 by repinementer on Thursday 28th of May 2009 03:36:05 AM
Old 05-28-2009
How to print Dissimilar keys and their values?

Hi guyz I have been using this script to find similar keys in 2 files and merge the keys along with their values. Therefore it prints similar keys by leaving dissimilar. Any one knows how to print only Dissimilar leaving Similar.

Help would be appreciated.

The script I'm using for similar ones is

awk 'FNR==NR{ a[$1]=$0;next}a[$1]!=""{print $1,a[$1]}' file2 file1

the files for the script for similarkeys is
Mac1-/home/>file1
1234
133
1345
134
23
4555
Mac1-/home/>file2
1234 tab kshgjkghj
100 tab dfghjk
23 tab drjghfg
134 tab drkhgjgj
1345 tab djghf
4555 tab khdjhgjfg
13tabjghhdgf
Mac1-/home/l>output

1234 1234 tab kshgjkghj
1345 1345 tab djghf
134 134 tab drkhgjgj
23 23 tab drjghfg
4555 4555 tab khdjhgjfg

The script I' trying to design has to do some thing like thisvfor dissimilar ones

Mac1-/home/l>output

100 tab dfghjk
13 tab jghhdgf
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

arrow keys / special keys

how to use the arrow keys in shell scripting. is there any special synatax / command for this. i just want to use the arrow keys for navigation. replies appreciated raguram R (3 Replies)
Discussion started by: raguramtgr
3 Replies

2. Shell Programming and Scripting

select values based on keys

HI The input 1st column has specific keys like 1 with value a,b and c. 2 with b,b,d and 3 with a,a a. when ever c appears as one of the values the result will be key ........ c (You can see in the out put as 1 w...... 6.... c) and same follows for d. Thanx:) I'm learning awk scripting. If... (3 Replies)
Discussion started by: repinementer
3 Replies

3. Shell Programming and Scripting

comparing the values of repeated keys in multiple columns

Hi Guyz The 1st column of the input file has repeated keys like x,y and z. The ist task is if the 1st column has unique key (say x) and then need to consider 4th column, if it is + symbol then subtract 2nd column value with 3rd column value (we will get 2(10-8)) or if it is - symbol subtract 3rd... (3 Replies)
Discussion started by: repinementer
3 Replies

4. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

5. Shell Programming and Scripting

Deleting keys and values-Awk

key pair is 1st and 6th column ex:a20 : p10 or a20 : p11 For every key pair if the vlaue(4th column) is the same then delete all the lines who has keypair and the value ex: a20 : p10 has value 1 only then delete those but a20 : p11 has different values 1,2 and 3 and keep those. input a20 ... (8 Replies)
Discussion started by: ruby_sgp
8 Replies

6. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

7. Shell Programming and Scripting

Extract values of duplicate keys

I have two questions that are related, so it would be great if you can help me with both! Question1: I have a file A that looks like this: a x b y b z c w I want to get something like: a x b y; z c w Given that a,b,c has no spaces. But the other letters might contain spaces. ... (2 Replies)
Discussion started by: Viernes
2 Replies

8. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

9. Shell Programming and Scripting

Generate separate files with similar and dissimilar contents

Hello experts, I have 2 files 1.txt (10,000 lines of text) and 2.txt (7500 lines of text). Both files have similar as well as dissimilar entries. Is there a way(s) where i can perform the following operations : 1. Generate a file which will have all similar lines. 2. Generate a file which... (7 Replies)
Discussion started by: H squared
7 Replies

10. UNIX for Beginners Questions & Answers

Calculate average from a given set of keys and values

Hello, I am writing a script which expects as its input a hash with student names as the keys and marks as the values. The script then returns array of average marks for student scored 60-70, 70-80, and over 90. Output expected 50-70 1 70-90 3 over 90 0 The test script so far... (4 Replies)
Discussion started by: nans
4 Replies
ypmatch(1)						      General Commands Manual							ypmatch(1)

NAME
ypmatch - print values of selected keys in Network Information Service map SYNOPSIS
domain] Remarks The Network Information Service (NIS) was formerly known as Yellow Pages (YP). Although the name has changed, the functionality of the service remains the same. DESCRIPTION
prints the values associated with one or more keys in a Network Information Service (NIS) map specified by mname. The mname can be either a mapname or a map nickname. A map nickname is a synonym by which a NIS map can be referenced. If multiple keys are specified, the same map is searched for an occurrence of each key. A match is made only when the case and length of a key is the same as that stored in the database. No pattern matching is available. If a key is not matched, a diagnostic message is pro- duced. Options recognizes the following command-line options: Before printing the value associated with a key, print the key followed by a colon This option is useful if the keys are not part of the values (as in a map), or so many keys were specified that the output could be confusing. Inhibit the translation of a map's nickname to its corresponding mapname. For example, fails because there is no map named whereas, is translated to Specify a domain other than the default domain, that is, the one returned by (see domainname(1)). Display the nickname for each NIS map. AUTHOR
was developed by Sun Microsystems, Inc. SEE ALSO
domainname(1), ypcat(1), ypserv(1M), ypfiles(4). ypmatch(1)
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy