Unix questions - match file

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > November 2006 > match file





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author match file
rogv24@yahoo.com

2006-11-13, 9:01 am


I have a sorted file1 that I want to make sure the keys in file1 are
taken out from file2.
Is there a command that can handle that?

Stephane CHAZELAS

2006-11-13, 9:01 am

2006-11-8, 10:30(-08), rogv24@yahoo.com:
>
> I have a sorted file1 that I want to make sure the keys in file1 are
> taken out from file2.
> Is there a command that can handle that?


I'm not quite sure what you mean, but you may want to have a
look at the join, comm and uniq commands.

--
Stéphane
John Gordon

2006-11-13, 9:01 am

In <1163010638.348908.17170@b28g2000cwb.googlegroups.com> rogv24@yahoo.com writes:

> I have a sorted file1 that I want to make sure the keys in file1 are
> taken out from file2.
> Is there a command that can handle that?


There is not a single command that will do that, no.

However, there are commands which, when used together, can probably do
what you want.

For example, you could probably use "awk" to extract the keys from each
file, then use "comm" or "diff" to compare the two key lists, and finally
use "sed" or "grep" to make a new copy of file2 which contains only the
keys you want.

--
John Gordon "... What with you being his parents and all,
gordon@panix.com I think that you could be trusted not to shaft
him." -- Robert Chang, rec.games.board

Ed Morton

2006-11-13, 9:01 am

John Gordon wrote:
> In <1163010638.348908.17170@b28g2000cwb.googlegroups.com> rogv24@yahoo.com writes:
>
>
>
>
> There is not a single command that will do that, no.
>
> However, there are commands which, when used together, can probably do
> what you want.
>
> For example, you could probably use "awk" to extract the keys from each
> file, then use "comm" or "diff" to compare the two key lists, and finally
> use "sed" or "grep" to make a new copy of file2 which contains only the
> keys you want.
>


awk can do it on it's own. It sounds like the OP want's something like this:

awk 'NR==FNR{keys[$0];next}!($0 in keys)' file1 file2

That'll delete every line from file2 that exists in file 1. If the keys
exist in specific fields of each line in each file, use $1, $2, etc.
instead of $0 to identify the key fields, e.g. if the key field in fil1
is field 3, and the key field in file2 is field 7, it'd be:

awk 'NR==FNR{keys[$3];next}!($7 in keys)' file1 file2

Regards,

Ed.
rogv24@yahoo.com

2006-11-13, 9:01 am



Thanks for the info:

I used comm -1 file1 file2 and it works fine.


Stephane CHAZELAS wrote:
> 2006-11-8, 10:30(-08), rogv24@yahoo.com:
>
> I'm not quite sure what you mean, but you may want to have a
> look at the join, comm and uniq commands.
>=20
> --=20
> St=E9phane


rogv24@yahoo.com

2006-11-13, 9:01 am



Thanks for the info:

I used comm -1 file1 file2 and it works fine.


Stephane CHAZELAS wrote:
> 2006-11-8, 10:30(-08), rogv24@yahoo.com:
>
> I'm not quite sure what you mean, but you may want to have a
> look at the join, comm and uniq commands.
>=20
> --=20
> St=E9phane


rogv24@yahoo.com

2006-11-13, 9:01 am



Thanks for the info:

I used comm -1 file1 file2 and it works fine.


Stephane CHAZELAS wrote:
> 2006-11-8, 10:30(-08), rogv24@yahoo.com:
>
> I'm not quite sure what you mean, but you may want to have a
> look at the join, comm and uniq commands.
>=20
> --=20
> St=E9phane


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com