Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Two input files and program
Hi I've just started to learn awk and I have a question. I can write very
simple scripts but this task I think is too difficult for me.
I have two input files
First contains data as follows separated with " "
1 1
1.12 2
1.13 4
1.24 5
and second file contains similar data :
1.02 1
1.13 2
1.20 3
1.28 5
This files are very big and I want to:
Compare fields in the second columns and if fields are equal I want awk to
substr field from first column of second file with first column of first
file.
So this script should do. Get first field in second column in second file,
search for the same field in second column first file and if they are equal
substr fields in first columns.If they aren't equal search in next field
For this example I gave awk should produce:
0.2 1
0.01 2
0.04 5

Tkanks for any answers



Report this thread to moderator Post Follow-up to this message
Old Post
Micha³
11-16-04 11:50 PM


Re: Two input files and program

Micha³ wrote:

> Hi I've just started to learn awk and I have a question. I can write very
> simple scripts but this task I think is too difficult for me.
> I have two input files
> First contains data as follows separated with " "
> 1 1
> 1.12 2
> 1.13 4
> 1.24 5
> and second file contains similar data :
> 1.02 1
> 1.13 2
> 1.20 3
> 1.28 5
> This files are very big and I want to:
> Compare fields in the second columns and if fields are equal I want awk to
> substr

ITYM "subtract" not "substr".

field from first column of second file with first column of first
> file.
> So this script should do. Get first field in second column in second file,

ITYM Get the second field in the first line in the second file.

> search for the same field in second column first file and if they are equa
l
> substr

ITYM "subtract" not "substr".

fields in first columns.If they aren't equal search in next field

ITYM If ther aren't equal search in the next line

> For this example I gave awk should produce:
> 0.2 1
> 0.01 2
> 0.04 5
>
> Tkanks for any answers

I assume the values in the second column of file2 are unique and that if
they aren't unique in file1 you want the same operation applied to all.

If all my assumptions above are correct, then this should so it (untested):

awk 'NR==FNR{f1[$2]=$1;next}
$2 in f1{$1=$1-f1[$2];print}' file2 file1

Regards,

Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:11 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.