Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

join based on line number when one file is missing lines

Tags
join, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 06-27-2011
join based on line number when one file is missing lines

I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like:
Code:
1 200.3 -0.3
2 201.7 -0.32
...
87 200.2 -0.314

I have another file which contains data that was taken at certain of these 87 positions. i.e.:

Code:
37 125
42 175
86 142

where the first number is the line number of the coordinates in the other file. Is there a way to get an output like:

Code:
37 201.2 -0.324 125
42 200.1 -0.311 175
86 203.0 -0.35 142

where I am pulling columns 2 & 3 from the first file with 87 lines, and column 4 from the second file (in this example with 3 lines but I want to be able to do more)?

I've tried using join to do this but it doesn't bring up anything!

Thanks!
Moderator's Comments:
join based on line number when one file is missing lines Please use code tags when posting data and code samples!

Last edited by vgersh99; 06-27-2011 at 07:09 PM.. Reason: code tags, please!
# 2  
Old 06-27-2011
Code:
nawk 'FNR==NR{data[$1]=$2;next} $1 in data {print $0, data[$1]}' dataFile coordinatesFile

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk join lines based on keyword alex2005 Shell Programming and Scripting 2 01-18-2017 02:05 PM
To check the missing file based on sequence number. Arun1992 Shell Programming and Scripting 5 04-22-2016 03:31 PM
Print lines based on line number and specified condition Anjan1 Shell Programming and Scripting 10 12-31-2014 03:41 PM
Split file based on number of blank lines Pratik4891 UNIX for Dummies Questions & Answers 8 04-02-2014 04:48 AM
Join lines from two files based on match pathunkathunk Shell Programming and Scripting 2 08-18-2013 03:55 PM
join 2 lines based on 1st field anurupa777 UNIX for Dummies Questions & Answers 1 07-29-2012 06:41 AM
Merge two non-consecutive lines based on line number or string munkee Shell Programming and Scripting 7 05-17-2011 06:33 PM
Delete lines based on line number novice_man Shell Programming and Scripting 2 01-28-2011 05:56 AM
Join in a single line variable number of lines cgkmal Shell Programming and Scripting 4 08-03-2009 06:52 AM
How can I get an if statement to execute based on number of lines in a file? LordJezo Shell Programming and Scripting 6 05-14-2004 10:50 AM


All times are GMT -4. The time now is 08:23 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password